Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Doctrine DQL无效参数编号:绑定变量的数量与令牌的数量不匹配_Php_Symfony_Doctrine Orm_Prepared Statement_Dql - Fatal编程技术网

Php Doctrine DQL无效参数编号:绑定变量的数量与令牌的数量不匹配

Php Doctrine DQL无效参数编号:绑定变量的数量与令牌的数量不匹配,php,symfony,doctrine-orm,prepared-statement,dql,Php,Symfony,Doctrine Orm,Prepared Statement,Dql,我得到错误无效参数编号:绑定变量的数量与此查询中的令牌数量不匹配 我真的不觉得有什么问题,有什么想法吗 public function getByPartial($q, Company $company) { $query = $this->createQueryBuilder('u') ->join('u.company',':company') ->where('u.firstName LIKE :q') ->

我得到错误
无效参数编号:绑定变量的数量与此查询中的令牌数量不匹配

我真的不觉得有什么问题,有什么想法吗

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')
        ->join('u.company','c')
        ->where('u.firstName LIKE :q1 OR u.lastName LIKE :q2')
        ->andWhere('c.id = :company_id')
        ->setParameters(array('company_id' => $company->getId(), 'q1' => '%'.$q.'%', 'q2' => '%'.$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();
}

仍然得到相同的错误。当我移除与公司的连接部分时,它似乎起作用了吗?