How to make multiple WHERE IN column query in Doctrine query builder?(如何在 Doctrine 查询生成器中进行多个 WHERE IN 列查询?)
问题描述
我想使用带有两列检查的 WHERE IN 语句更新 db 中的多条记录.
I would like to update multiple records in db using WHERE IN statement with two column check.
Pure MySql 原始查询看起来像这样.. 它可以工作:
Pure MySql raw query looks something like this.. and it works:
UPDATE poll_quota q SET q.count = q.count+1 WHERE q.form_id=14 AND ((q.field_id,q.value) IN (('A',1),('B',1)))
我的代码:
$this->createQueryBuilder("q")
->update()
->set("q.count","q.count+1")
->where("q.form_id=:form_id")
->andWhere("((q.field_id,q.value) IN (:wherein))")
->setParameter(":form_id",$form_id)
->setParameter(":wherein",$where_in)
->getQuery()
->execute()
;
输出:
[Syntax Error] line 0, col 103: Error: Expected DoctrineORMQueryLexer::T_CLOSE_PARENTHESIS, got ','
[1/2] QueryException: UPDATE EdgePollBundleEntityQuota q SET q.count = q.count+1 WHERE q.form_id=:form_id AND ((q.field_id,q.value) IN (:wherein)) +
尝试这样做,也不起作用:
Attemp to do sth like this, also doesn't work:
[...]->andWhere("((q.field_id,q.value) IN ({$where_in}))")
$where_in 包含这样的字符串:
$where_in contains string like this:
"('A',1),('B',1)"
推荐答案
DQL 不允许在 WHERE IN 语句中使用多个列,因为并非所有 DBMS 都支持它.您可以使用 $this->getEntityManager()->getConnection()->executeUpdate()
DQL doesn't allow using multiple columns in a WHERE IN statement since not all DBMS support it. You can run it with the raw SQL using $this->getEntityManager()->getConnection()->executeUpdate()
这篇关于如何在 Doctrine 查询生成器中进行多个 WHERE IN 列查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Doctrine 查询生成器中进行多个 WHERE IN 列查询?
基础教程推荐
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
