Zend-framework DB:OR 代替 AND 运算符

发布于 2024-09-15 13:20:24 字数 663 浏览 8 评论 0原文

有这样的 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%')...

您的帮助将不胜感激。

have such zend query:

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

In other words it looks like:

SELECT `some_table`.* FROM `some_table` WHERE (title LIKE '%nice house%') AND (description LIKE '%nice house%') AND (verified=1 AND activated=1)

If I have couple AND sentences, zend connect it through AND operator. How can I connect it with OR operator ? Cause I need:

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

Your help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的十字路口 2024-09-22 13:20:24
$this->_table->select()->orWhere($condition);

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

$this->_table->select()->orWhere($condition);

To build more complexe queries (i.g. sub-conditions) you might have to use $this->table->getAdapter()->quoteInto() and write your SELECT manually.

暖阳 2024-09-22 13:20:24

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

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

The others answers here do not work (anymore?), the current solution is to call nest() and unnest() in the where clause:

$select->where
    ->nest()
        ->equalTo('column1', 1)
        ->or
        ->equalTo('column2', 2)
    ->unnest()
    ->and
    ->equalTo('column3', 3);
哭了丶谁疼 2024-09-22 13:20:24

我已经实现了你的 zend 查询

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

I have implemented your zend query

$select = $this->_table
               ->select()
               ->where('title LIKE  ?', '%'.$searchWord.'%')
               ->ORwhere('description LIKE  ?', '%'.$searchWord.'%')
               ->where('verified=1 AND activated=1');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文