加入收藏 | 设为首页 | 会员中心 | 我要投稿 鄂州站长网 (https://www.0711zz.com/)- 数据分析、网络、云渲染、应用安全、大数据!
当前位置: 首页 > 数据库 > MsSql > 正文

sql – 使用setParameters的Doctrine2

发布时间:2020-08-03 02:14:44 所属栏目:MsSql 来源:互联网
导读:当我似乎在我的查询中使用参数时,我收到一个错误 Invalid parameter number: number of bound variables does not match number of tokens 这是我的代码 public function GetGeneralRatingWithUserRights($user, $thread_array){ $parameter

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

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

(编辑:鄂州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读