gpt4 book ai didi

php - Doctrine DQL 无效参数编号 : number of bound variables does not match number of tokens

转载 作者:可可西里 更新时间:2023-10-31 23:21:51 24 4
gpt4 key购买 nike

我在这个查询中收到错误无效的参数编号:绑定(bind)变量的数量与标记的数量不匹配

我真的没有看到问题,有什么想法吗?

public function getByPartial($q, Company $company)
{

$query = $this->createQueryBuilder('u')
->join('u.company',':company')
->where('u.firstName LIKE :q')
->orWhere('u.lastName LIKE :q')
->setParameters(array('company' => $company, 'q' => '%'.$q.'%'))
->getQuery();
return $query->getResult();

}

最佳答案

公司不能作为参数,您只需指定一个别名,例如:

public function getByPartial($q, Company $company)
{
$query = $this->createQueryBuilder('u')
->addSelect('c')
->join('u.company','c')
->where('u.firstName LIKE :q OR u.lastName LIKE :q')
->andWhere('c.id = :companyId')
->setParameters(array('companyId' => $company->getId(), 'q' => '%'.$q.'%'))
->getQuery();
return $query->getResult();
}

关于php - Doctrine DQL 无效参数编号 : number of bound variables does not match number of tokens,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17338232/

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