问题
I have a SELECT object which contains a WHERE.
I can return the WHERE using getPart(Zend_Db_Select::WHERE)
, this returns something like this:
array
0 => string "(clienttype = 'agent')"
1 => string "AND (nextpayment < (NOW() - INTERVAL 1 DAY))"
This array seems pretty useless as I cannot do this with it
$client->update(array("paymentstatus" => "lapsed"), $where);
Or even put it into another SELECT object. Is there a way of getting a more useful representation of the WHERE statement from the SELECT object?
Thanks
EDIT
The best I have come up with so far is
$where = new Zend_Db_Expr(implode(" ", $select->getPart(Zend_Db_Select::WHERE)));
回答1:
Your first choice, $client->update(...)
would work, if getParts omitted the 'AND' from the second part of the where clause.
I'm pretty sure your only choice is to:
- use your second option (probably safest depending on how complex the where clauses are) -or-
- iterate through the $where returned and remove the leading 'AND', 'OR' that may exist.
来源:https://stackoverflow.com/questions/4366749/zend-framework-re-use-where-clause-returned-from-zend-db-selectgetpart