使用setParameters的Doctrine2
技术问答
259 人阅读
|
0 人回复
|
2023-09-13
|
当我似乎在查询中使用参数时,我会犯错误8 S' R$ A- S9 M: j A: N
无效参数编号:绑定变量的数量与令牌的数量不匹配
! ?/ J% e: [# L* ^5 I这是我的代码
0 ^& e/ y9 }3 S) m4 W3 spublic function GetGeneralRatingWithUserRights($user,$thread_array){ $parameters = array( thread' => $thread_array['threadtype' => '%'.$thread_array['type']. $dql = 'SELECT p.type,AVG(p.value) FROM TrackerMembersBundle:Rating p GROUP BY p.thread,p.type $query = $this->em->createQuery($dql) ->setParameters($parameters); $ratings = $query->execute(); return $ratings;}参数组如何正确配置?& C7 y, x/ ]" O6 y1 X
$ p l7 b: o; `* r0 @4 A% y 解决方案:
( t8 J0 p4 r/ E! N& _ 您在查询中没有包含参数。$ s, p6 _! h& i
$parameters = array( thread' => $thread_array['thread type' => '%'.$thread_array['type'].'%');$dql = 'SELECT p.type,AVG(p.value) FROM TrackerMembersBundle:Rating p WHERE p.thread=:thread AND type LIKE :type GROUP BY p.thread,p.type';$query = $this->em->createQuery($dql) ->setParameters($parameters); |
|
|
|
|
|