加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 使用setParameters的Doctrine2

发布时间:2020-12-12 05:54:33 所属栏目:MsSql教程 来源:网络整理
导读:当我似乎在我的查询中使用参数时,我收到一个错误 Invalid parameter number: number of bound variables does not match number of tokens 这是我的代码 public function GetGeneralRatingWithUserRights($user,$thread_array){ $parameters = array( 'thread
当我似乎在我的查询中使用参数时,我收到一个错误

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

(编辑:李大同)

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

    推荐文章
      热点阅读