sql – 使用setParameters的Doctrine2

当我似乎在我的查询中使用参数时,我收到一个错误

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);

请参阅文档中的示例:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#dql-select-examples

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...