sql – 使用setParameters的Doctrine2
发布时间:2020-08-03 00:28:02  所属栏目:MsSql  来源:互联网 
            导读:当我似乎在我的查询中使用参数时,我收到一个错误 Invalid parameter number: number of bound variables does not match number of tokens 这是我的代码 public function GetGeneralRatingWithUserRights($user, $thread_array){ $parameter
                
                
                
            | 
                         当我似乎在我的查询中使用参数时,我收到一个错误 
 这是我的代码 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 (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
