我正在使用准备好的语句来插入数据。我得到了'Invalid parameter number: number of bound variables does not match number of tokens.'
我已经尝试转储准备好的语句,但我无法发现不匹配。有没有办法找出不匹配的地方。
$i = 0 ; $j = 0 ; $k = 0 ; $l = 0 ; $str = "" ; $region_str = '' ;
$occasion_str = '' ; $flavor_str = '' ;
foreach($result->WINES->WINE as $w)
{
if($i == 0)
$str = "(:wineid$i,:acctid$i,:brand$i,:varietal$i,:descr$i,:prop$i,:color$i,:case$i,:url$i)" ;
else
$str .= ", (:wineid$i,:acctid$i,:brand$i,:varietal$i,:descr$i,:prop$i,:color$i,:case$i,:url$i)" ;
foreach($w->REGIONS->REGION as $region)
{
if($j == 0)
$region_str = "(:rwineid$i,:region$j)" ;
else
$region_str .= ", (:rwineid$i,:region$j)" ;
$j++ ;
}
foreach($w->OCCASIONS->OCCASION as $o)
{
if($k == 0)
$occasion_str = "(:owineid$i,:occasion$k)" ;
else
$occasion_str .= ", (:owineid$i,:occasion$k)" ;
$k++ ;
}
foreach($w->FLAVORS->FLAVOR as $f)
{
if($l == 0)
$flavor_str = "(:fwineid$l,:flavor$l)" ;
else
$flavor_str .= ", (:fwineid$l,:flavor$l)" ;
$l++ ;
}
$i++ ;
}
$sql = " Delete from wines ;
Insert into wines (wineid,acctid,brandname,varietal,description,propreitaryname,color,caseproduction,url)
values
$str ;
Delete from wine_regions ;
Insert into wine_regions (wineid,region) values $region_str ;
Delete from wine_occasions ;
Insert into wine_occasions (wineid,occasion) values $occasion_str ;
Delete from wine_flavors ;
Insert into wine_flavors (wineid,flavor) values $flavor_str ; " ;
if($str != "")
{
$command = Yii::app()->db->createCommand($sql) ;
// $command_2 = Yii::app()->db->createCommand($sql_2) ;
$i = 0 ; $j = 0 ; $k = 0 ; $l = 0 ;
foreach($result->WINES->WINE as $wine)
{
$command->bindValue(":wineid$i",$wine->WINEID,PDO::PARAM_STR) ;
// $command_2->bindValue(":wineid$i",$i,PDO::PARAM_STR) ;
$command->bindValue(":acctid$i",$wine->ACCTID,PDO::PARAM_STR) ;
$command->bindValue(":brand$i",$wine->BRANDNAME,PDO::PARAM_STR) ;
$command->bindValue(":varietal$i",$wine->VARIETAL,PDO::PARAM_STR) ;
$command->bindValue(":descr$i",$wine->DESCRIPTION,PDO::PARAM_STR) ;
$command->bindValue(":prop$i",$wine->PROPRIETARYNAME,PDO::PARAM_STR) ;
$command->bindValue(":color$i",$wine->COLOR,PDO::PARAM_STR) ;
$command->bindValue(":case$i",$wine->CASEPRODUCTION,PDO::PARAM_STR) ;
$command->bindValue(":url$i",$wine->URL,PDO::PARAM_STR) ;
foreach((array)$wine->REGIONS->REGION as $region)
{
$command->bindValue(":rwineid$j",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":region$j",$region,PDO::PARAM_STR) ;
$j++ ;
}
foreach((array)$wine->OCCASIONS->OCCASION as $o)
{
$command->bindValue(":owineid$k",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":occasion$k",$o,PDO::PARAM_STR) ;
$k++ ;
}
foreach((array)$wine->FLAVORS->FLAVOR as $f)
{
$command->bindValue(":fwineid$l",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":flavor$l",$f,PDO::PARAM_STR) ;
$l++ ;
}
$i++ ;
}
var_dump($command) ;
$command->execute() ;
}