Zend框架:重用Zend_Db_Select :: getPart()返回的WHERE子句 [英] Zend Framework: Re-use WHERE clause returned from Zend_Db_Select::getPart()

查看:129
本文介绍了Zend框架:重用Zend_Db_Select :: getPart()返回的WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含WHERE的SELECT对象.

I have a SELECT object which contains a WHERE.

我可以使用getPart(Zend_Db_Select::WHERE)返回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);

或者甚至将其放入另一个SELECT对象中.有没有一种方法可以从SELECT对象中获得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?

谢谢

编辑

EDIT

到目前为止,我想出的最好的方法是

The best I have come up with so far is

$where = new Zend_Db_Expr(implode(" ", $select->getPart(Zend_Db_Select::WHERE)));

推荐答案

您的第一选择$client->update(...)将起作用,如果 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:

  1. 使用第二个选项(可能最安全,具体取决于where子句的复杂程度)-或-
  2. 在返回的$ where处进行迭代,并删除可能存在的前导"AND","OR".

这篇关于Zend框架:重用Zend_Db_Select :: getPart()返回的WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆