如何向 Zend Table Select 添加复杂的 where 子句?
我搜索了网络,但找不到任何可以向我展示良好可靠示例的内容。我的问题基本上是这样的:
如何转换:
SELECT * FROM table WHERE ((a = 1 AND b = 2) OR (c = 3 OR c = 4)) AND d = 5;
Zend 语法与此类似:
$this -> 选择() ->from($this->_schema.'.'.$this->_name) ->where('a = ?', '1');
那么如何才能做到呢?
预先非常感谢。
I searched the Web and could not find anything that would show me a good solid example. My question is basically this:
How do I convert this:
SELECT * FROM table WHERE ((a = 1 AND b = 2) OR (c = 3 OR c = 4)) AND d = 5;
To Zend syntax similar to this:
$this
->select()
->from($this->_schema.'.'.$this->_name)
->where('a = ?', '1');
So how can it be done?
Thank a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有类似的问题。请参阅此处答案中的代码示例:使用 Zend_Db_Table_Abstract 对 WHERE 子句进行分组
所以你最终会得到类似的结果:
这会给你:
I had a similar problem. See the code example in the answer here: Grouping WHERE clauses with Zend_Db_Table_Abstract
So you would end up with something like:
Which would give you:
1)为所有组建立条件Where/orWhere:
使用getPart()方法获取where条件。
2) 接下来,重置当前选择对象的 where 部分:
3) 最后,根据需要使用 where 条件:
http://framework.zend.com/manual/1.12/ru/zend.db.select.html
1) Build a condition for all groups Where/orWhere:
Use getPart() method to get the where condition.
2) Next, reset the where part of current select object:
3) Finally, use where condition as you want:
http://framework.zend.com/manual/1.12/ru/zend.db.select.html
根据 Zend Framework 网站上的 留言板帖子,这可能是不可能的。
Per a message board post on the Zend Framework website, this may not be possible.
Edit
Zend_Db_Select->where
的数组功能仅设计用于与IN
子句一起使用。原创
<罢工>
正如 Peder 所说,你不能嵌套
orWhere
,但你可以将多个参数传递给where
和orWhere
。Edit
The array functionality of
Zend_Db_Select->where
is designed only for using it with theIN
clause.Original
As Peder said you can't nest
orWhere
but you can pass multiple arguments intowhere
andorWhere
.