开发者

Zend Framework: Re-use WHERE clause returned from Zend_Db_Select::getPart()

开发者 https://www.devze.com 2023-01-29 06:03 出处:网络
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:

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 pret开发者_如何学Cty 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)));


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:

  1. use your second option (probably safest depending on how complex the where clauses are) -or-
  2. iterate through the $where returned and remove the leading 'AND', 'OR' that may exist.
0

精彩评论

暂无评论...
验证码 换一张
取 消