Saya memiliki kode berikut yang memunculkan pengecualian Invalid parameter number: number of bound variables does not match number of tokens
. Namun ketika saya mencetak parameter terdaftar, parameter saya muncul.
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>";
}
Mencetak $this->qb->getParameters();
menunjukkan kepada saya Array ( [configuration_id] => 1 )
, dan menghapus klausa parameter tempat dan pengaturan saya mencegah terjadinya pengecualian. Terakhir, (dan dapatkan ini), jika saya menghapus klausa Where tetapi tetap mempertahankan parameternya, tidak ada pengecualian yang terjadi. Saya agak bingung.
where('t.printconfiguration = :configuration_id')->setParameter('configuration_id', $configuration_id);
dan pengecualian yang sama masih terjadi. Saya dapat meneruskannya secara langsung seperti yang saya lakukan pada pernyataancase
, tetapi hal itu menggagalkan tujuan penggunaan PDO... - person Nick   schedule 10.11.2011