【问题标题】:Zend-framework DB: OR instead of AND operatorZend-framework DB:OR 而不是 AND 运算符
【发布时间】:2010-08-21 07:40:03
【问题描述】:

有这样的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 句子,zend 通过 AND 运算符连接它。如何将其与 OR 运算符连接?因为我需要:

...(title LIKE '%nice house%') OR (description LIKE '%nice house%')...

您的帮助将不胜感激。

【问题讨论】:

  • 我认为只考虑 sql.. 运算符优先级,因为这些查询将被转换为纯 sql。我只是建议,因为我也有这个疑问并来到这里

标签: zend-framework zend-db


【解决方案1】:
$this->_table->select()->orWhere($condition);

要构建更复杂的查询(例如子条件),您可能必须使用 $this->table->getAdapter()->quoteInto() 并手动编写 SELECT。

【讨论】:

    【解决方案2】:

    这里的其他答案不起作用(不再?),当前的解决方案是在 where 子句中调用 nest() 和 unnest():

    $select->where
        ->nest()
            ->equalTo('column1', 1)
            ->or
            ->equalTo('column2', 2)
        ->unnest()
        ->and
        ->equalTo('column3', 3);
    

    【讨论】:

    【解决方案3】:

    我已经实现了你的 zend 查询

    $select = $this->_table
                   ->select()
                   ->where('title LIKE  ?', '%'.$searchWord.'%')
                   ->ORwhere('description LIKE  ?', '%'.$searchWord.'%')
                   ->where('verified=1 AND activated=1');
    

    【讨论】:

      猜你喜欢
      • 2014-04-13
      • 2018-04-30
      • 2022-08-17
      • 2023-03-12
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 2015-02-26
      • 2014-04-22
      相关资源
      最近更新 更多