有这样的zend查询:
$select = $this->_table
->select()
->where('title LIKE ?', '%'.$searchWord.'%')
->where('description LIKE ?', '%'.$searchWord.'%')
->where('verified=1 AND activated=1');
换句话说,它看起来像:
SELECT `some_table`.* FROM `some_table` WHERE (title LIKE '%nice house%') AND (description LIKE '%nice house%') AND (verified=1 AND activated=1)
如果我有几个AND语句,则通过AND运算符连接它。如何将其与OR运算符连接?因为我需要:
...(title LIKE '%nice house%') OR (description LIKE '%nice house%')...
我们将不胜感激。
答案 0 :(得分:25)
$this->_table->select()->orWhere($condition);
要构建更复杂的查询(即子条件),您可能必须使用$this->table->getAdapter()->quoteInto()
并手动编写SELECT。
答案 1 :(得分:2)
这里的其他答案不起作用(不再?),当前的解决方案是在where子句中调用nest()和unnest():
$select->where
->nest()
->equalTo('column1', 1)
->or
->equalTo('column2', 2)
->unnest()
->and
->equalTo('column3', 3);
答案 2 :(得分:1)
我已实施您的zend查询
$select = $this->_table
->select()
->where('title LIKE ?', '%'.$searchWord.'%')
->ORwhere('description LIKE ?', '%'.$searchWord.'%')
->where('verified=1 AND activated=1');