Doctrine2使用setParameters [英] Doctrine2 using setParameters
本文介绍了Doctrine2使用setParameters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我似乎在查询中使用参数时,我收到错误
when i seem to use parameters in my query, i get an error
参数号无效:绑定变量的数量不匹配令牌数
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;
}
如何正确配置参数数组?
how do i configure the paramters array properly?
推荐答案
您没有在查询中包含参数。
You didn't include your parameters in the query.
$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);
See examples in the documentation: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#dql-select-examples
这篇关于Doctrine2使用setParameters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文