gpt4 book ai didi

sql - Doctrine2 使用 setParameters

转载 作者:行者123 更新时间:2023-12-04 04:49:14 27 4
gpt4 key购买 nike

当我似乎在查询中使用参数时,出现错误

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

关于sql - Doctrine2 使用 setParameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9988866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com