php – 如何在Doctrine查询生成器中进行多个WHERE IN列查询?
作者:互联网
我想使用带有两列检查的WHERE IN语句更新db中的多条记录.
纯MySql原始查询看起来像这样..它的工作原理:
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 Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
[1/2] QueryException: UPDATE Edge\PollBundle\Entity\Quota q SET q.count = q.count+1 WHERE q.form_id=:form_id AND ((q.field_id,q.value) IN (:wherein)) +
尝试这样做,也行不通:
[...]->andWhere("((q.field_id,q.value) IN ({$where_in}))")
$where_in包含这样的字符串:
"('A',1),('B',1)"
解决方法:
DQL不允许在WHERE IN语句中使用多个列,因为并非所有DBMS都支持它.您可以使用$this-> getEntityManager() – > getConnection() – > executeUpdate()使用原始SQL运行它
标签:php,mysql,doctrine,symfony,where-in 来源: https://codeday.me/bug/20190519/1137099.html