当我似乎在我的查询中使用参数时,我收到一个错误
Invalid parameter number: number of bound variables does not match number of tokens
这是我的代码
public function GetGeneralRatingWithUserRights($user,$thread_array) { $parameters = array( 'thread' => $thread_array['thread'],'type' => '%'.$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; }
如何正确配置参数数组?
解决方法
您没有在查询中包含参数.
$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);