Doctrine orm 条令查询生成器未注册参数?

Doctrine orm 条令查询生成器未注册参数?,doctrine-orm,symfony,query-builder,Doctrine Orm,Symfony,Query Builder,我有以下代码抛出异常无效参数编号:绑定变量的数量与令牌的数量不匹配。然而,当我打印注册的参数时,我的参数就会显示出来 public function getUnitPriceFor($entityType,$entityID,$qty,$configuration_id) { $this->qb = $this->getEntityManager()->createQueryBuilder(); $this->qb ->select($this-

我有以下代码抛出异常无效参数编号:绑定变量的数量与令牌的数量不匹配。然而,当我打印注册的参数时,我的参数就会显示出来

public function getUnitPriceFor($entityType,$entityID,$qty,$configuration_id)
{
    $this->qb = $this->getEntityManager()->createQueryBuilder();
    $this->qb   ->select($this->_entities[$entityType]['select'])
                // for Base this would be ->select(array('t','c','w','g'))
                // for the other cases below, like website, it's array('t','w')
                ->from('AcmeBundle:PriceTier', 't');

    switch($entityType) :
        case 'base' :
            $this->qb   ->leftJoin('t.customers','c')
                        ->leftJoin('t.customergroups','g')
                        ->leftJoin('t.websites','w');
        break;
        case 'website' :
            $this->qb   ->join('t.websites','w','WITH','w.id = '.$entityID);
        break;
        case 'custgrp' :
            $this->qb   ->join('t.customergroups','g','WITH','g.id = '.$entityID);
        break;
        case 'cust' :
            $this->qb   ->join('t.customers','t','WITH','t.id = '.$entityID);
        break;
    endswitch;

    $this->qb           ->where('t.printconfiguration = :configuration_id');
    $this->qb           ->setParameter('configuration_id', $configuration_id);

    print_r( $this->qb->getParameters() );

    $dql = $this->qb->getDQL();

    echo"<pre>";
    print_r($this->getEntityManager()->createQuery($dql)->getArrayResult());
    echo"</pre>";
}
打印$this->qb->getParameters;显示数组[configuration_id]=>1,删除我的where和set参数子句可防止发生异常。最后,如果删除where子句但保留参数集,则不会发生异常。我很困惑。

显然$dql=$this->qb->getDQL;不会传递参数

我需要改变

$query = $this->qb->getQuery();

echo"<pre>";
print_r($query->getArrayResult());
echo"</pre>";


例外情况是发生在每个“案例”中还是只发生在某些“案例”中?另外,您是否尝试过将$configuration\u id直接传递给WHERE子句而不是使用setParameter?啊,其他情况下可能会由于select语句引发语义错误-我已经纠正了这一点,是的,任何情况下都是例外。我确实尝试了其中的't.printconfiguration=:configuration\u id'->setParameter'configuration\u id',$configuration\u id;同样的异常仍然发生。我可以像在案例陈述中那样直接传递它,但这几乎违背了使用PDO的目的……很高兴你找到了答案。你能解释一下你所说的破坏使用PDO的目的是什么意思吗?我并不反对——我只是直接传入了我的参数来保存一些代码,我很好奇是否有什么原因我不应该这样做。如果方便的话,很乐意在聊天中讨论。上述功能主要用于准备语句和存储过程。它还具有一些固有的sql注入保护。最后,有一个关于占位符的部分。
$query = $this->qb->getQuery();

echo"<pre>";
print_r($query->getArrayResult());
echo"</pre>";