ฉันมีรหัสต่อไปนี้ซึ่งมีข้อยกเว้น Invalid parameter number: number of bound variables does not match number of tokens
แต่เมื่อฉันพิมพ์พารามิเตอร์ที่บันทึกไว้ พารามิเตอร์ของฉันก็แสดงขึ้นมา
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();
แสดงให้ฉันเห็น Array ( [configuration_id] => 1 )
และการลบคำสั่งพารามิเตอร์ตำแหน่งและการตั้งค่าของฉันจะป้องกันไม่ให้เกิดข้อยกเว้น สุดท้ายนี้ (และรับสิ่งนี้) ถ้าฉันลบ Where clause ของฉันออกแต่คงการตั้งค่าพารามิเตอร์ไว้ ก็ไม่มีข้อยกเว้นเกิดขึ้น ฉันค่อนข้างสับสน
where('t.printconfiguration = :configuration_id')->setParameter('configuration_id', $configuration_id);
แล้ว แต่ยังคงมีข้อยกเว้นเดียวกันนี้เกิดขึ้น ฉันสามารถส่งผ่านมันได้โดยตรงเหมือนกับที่ฉันทำในคำสั่งcase
แต่นั่นค่อนข้างขัดต่อวัตถุประสงค์ของการใช้ PDO... - person Nick   schedule 10.11.2011