Zend Framework:重用从 Zend_Db_Select::getPart() 返回的 WHERE 子句
我有一个包含 WHERE 的 SELECT 对象。
我可以使用 getPart(Zend_Db_Select::WHERE)
返回 WHERE,这会返回类似这样的内容:
array
0 => string "(clienttype = 'agent')"
1 => string "AND (nextpayment < (NOW() - INTERVAL 1 DAY))"
这个数组似乎毫无用处,因为我无法用它执行此操作
$client->update(array("paymentstatus" => "lapsed"), $where);
,甚至无法将其放入另一个 SELECT 对象中。有没有办法从 SELECT 对象获取 WHERE 语句的更有用的表示形式?
谢谢
编辑
到目前为止我想出的最好的办法是
$where = new Zend_Db_Expr(implode(" ", $select->getPart(Zend_Db_Select::WHERE)));
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)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个选择
$client->update(...)
会起作用,if getParts 省略了 where 子句第二部分中的“AND”。我很确定您唯一的选择是:
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: