1. <small id='EzSVD'></small><noframes id='EzSVD'>

    2. <tfoot id='EzSVD'></tfoot><legend id='EzSVD'><style id='EzSVD'><dir id='EzSVD'><q id='EzSVD'></q></dir></style></legend>
      • <bdo id='EzSVD'></bdo><ul id='EzSVD'></ul>
      <i id='EzSVD'><tr id='EzSVD'><dt id='EzSVD'><q id='EzSVD'><span id='EzSVD'><b id='EzSVD'><form id='EzSVD'><ins id='EzSVD'></ins><ul id='EzSVD'></ul><sub id='EzSVD'></sub></form><legend id='EzSVD'></legend><bdo id='EzSVD'><pre id='EzSVD'><center id='EzSVD'></center></pre></bdo></b><th id='EzSVD'></th></span></q></dt></tr></i><div id='EzSVD'><tfoot id='EzSVD'></tfoot><dl id='EzSVD'><fieldset id='EzSVD'></fieldset></dl></div>

      使用 PHP Doctrine ORM 的复杂 WHERE 子句

      Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
          <tbody id='4lIoJ'></tbody>
          <legend id='4lIoJ'><style id='4lIoJ'><dir id='4lIoJ'><q id='4lIoJ'></q></dir></style></legend>
              <bdo id='4lIoJ'></bdo><ul id='4lIoJ'></ul>
              <tfoot id='4lIoJ'></tfoot>
              <i id='4lIoJ'><tr id='4lIoJ'><dt id='4lIoJ'><q id='4lIoJ'><span id='4lIoJ'><b id='4lIoJ'><form id='4lIoJ'><ins id='4lIoJ'></ins><ul id='4lIoJ'></ul><sub id='4lIoJ'></sub></form><legend id='4lIoJ'></legend><bdo id='4lIoJ'><pre id='4lIoJ'><center id='4lIoJ'></center></pre></bdo></b><th id='4lIoJ'></th></span></q></dt></tr></i><div id='4lIoJ'><tfoot id='4lIoJ'></tfoot><dl id='4lIoJ'><fieldset id='4lIoJ'></fieldset></dl></div>

                <small id='4lIoJ'></small><noframes id='4lIoJ'>

                本文介绍了使用 PHP Doctrine ORM 的复杂 WHERE 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 PHP Doctrine ORM 来构建我的查询.但是,我似乎不太明白如何使用 DQL(Doctrine Query Language)编写以下 WHERE 子句:

                I'm using the PHP Doctrine ORM to build my queries. However, I can't quite seem to figure how to write the following WHERE clause using DQL (Doctrine Query Language):

                WHERE name='ABC' AND (category1 = 'X' OR category2 = 'X' OR category3 = 'X') 
                AND price > 10
                

                如何指定括号的位置?

                我目前的 PHP 代码是这样的:

                What I currently have in my PHP code is this:

                ->where('name = ?', 'ABC')
                ->andWhere('category1 = ?', 'X')
                ->orWhere('category2 = ?', 'X')
                ->orWhere('category3 = ?', 'X')
                ->andWhere('price > ?', 10)
                

                但这会产生类似的东西

                WHERE name='ABC' AND category1 = 'X' OR category2 = 'X' OR category3 = 'X' 
                AND price > 10
                

                由于操作顺序,它不会返回预期的结果.

                which, due to order of operations, doesn't return the intended results.

                另外,where"、andWhere"和addWhere"方法有区别吗?

                Also, is there a difference between the "where", "andWhere", and "addWhere" methods?

                更新好的,看起来你不能使用 DQL 进行复杂的查询,所以我一直在尝试手动编写 SQL 并使用 andWhere() 方法来添加它.但是,我正在使用 WHERE..IN 并且 Doctrine 似乎正在剥离我的括号:

                UPDATE Ok, it seems like you can't do complex queries using DQL, so I've been trying to write the SQL manually and use the andWhere() method to add it. However, I'm using WHERE..IN and Doctrine seems to be stripping out my enclosing parentheses:

                $q->andWhere("(category1 IN $subcategory_in_clause
                            OR category2 IN $subcategory_in_clause 
                            OR category3 IN $subcategory_in_clause)");
                

                推荐答案

                根据我的经验,每个复杂的 where 函数都分组在括号内(我使用的是 Doctrine 1.2.1).

                From my experience, each complex where function is grouped within parenthesis (I'm using Doctrine 1.2.1).

                $q->where('name = ?', 'ABC')
                  ->andWhere('category1 = ? OR category2 = ? OR category3 = ?', array('X', 'X', 'X'))
                  ->andWhere('price < ?', 10)
                

                产生以下 SQL:

                WHERE name = 'ABC' 
                  AND (category1 = 'X' OR category2 = 'X' OR category3 = 'X')
                  AND price < 10
                

                这篇关于使用 PHP Doctrine ORM 的复杂 WHERE 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                <small id='2Bjt3'></small><noframes id='2Bjt3'>

                    <bdo id='2Bjt3'></bdo><ul id='2Bjt3'></ul>

                        <tbody id='2Bjt3'></tbody>
                    1. <legend id='2Bjt3'><style id='2Bjt3'><dir id='2Bjt3'><q id='2Bjt3'></q></dir></style></legend>

                          <tfoot id='2Bjt3'></tfoot>
                        • <i id='2Bjt3'><tr id='2Bjt3'><dt id='2Bjt3'><q id='2Bjt3'><span id='2Bjt3'><b id='2Bjt3'><form id='2Bjt3'><ins id='2Bjt3'></ins><ul id='2Bjt3'></ul><sub id='2Bjt3'></sub></form><legend id='2Bjt3'></legend><bdo id='2Bjt3'><pre id='2Bjt3'><center id='2Bjt3'></center></pre></bdo></b><th id='2Bjt3'></th></span></q></dt></tr></i><div id='2Bjt3'><tfoot id='2Bjt3'></tfoot><dl id='2Bjt3'><fieldset id='2Bjt3'></fieldset></dl></div>