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

人走茶凉 提交于 2019-12-10 19:59:57

问题


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:

  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.


来源:https://stackoverflow.com/questions/4366749/zend-framework-re-use-where-clause-returned-from-zend-db-selectgetpart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!