public function search($params)
{
$qb = $this->createQueryBuilder('auto');
if (isset($params['manufacturer'])) {
$qb->join('auto.manufacturer', 'man')
->where('man.manufacturer = :manufacturer')
->setParameter('manufacturer', $params['manufacturer']);
}
if (isset($params['model'])) {
$qb->join('auto.model', 'mod')
->where('mod.model = :model')
->setParameter('model', $params['model']);
}
return $qb->getQuery()->getResult();
}
查询返回错误:
参数号无效:绑定变量数不匹配 令牌数量
答案 0 :(得分:6)
将where
替换为andWhere
功能。因为当你有2个参数时,你首先将where where条件替换为where where条件,结果你有2个绑定参数只有一个标记。