SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

时间:2012-07-15 05:39:10

标签: sql pdo

我的代码产生错误:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

但我算了,没有遗漏的冒号,所有的绑定参数都在那里......是什么导致了这个错误?

参考下面的代码:

try{
    $pdo->beginTransaction();

    $insert1 = $pdo->prepare("INSERT INTO spo (spo_prefix,datecreated,destinationID,vendorID,grade,flute,qty,wdat,ldat,scoreline,due,remark,isowarrant,area_m,area_ft,supplyIDs,qty_waste,expectedPrice) VALUES (:spoprefix,:nowdate,:location,:selvid,:cgrade,:cflute,:vendorqty,:wdat,:ldat,:scoreline,:duedate,:vendorremark,:iso,:squarem,:squareft,:siid,:wasteqty,:thisprice)");

    $resultB = $pdo->prepare("SELECT vendorname FROM vendorDefinition WHERE id=:svid LIMIT 1");
    $resultC = $pdo->prepare("SELECT destinationName FROM shipDestination WHERE id=:locationselect LIMIT 1");

    $insert1->execute(array(":spoprefix"=>$_POST['SPOprefix'],
                            ":nowdate"=>$nowdate,
                            ":location"=>$_POST['locationselect'],
                            ":selvid"=>$_POST['selectedVID'],
                            ":cgrade"=>$_POST['const_grade'],
                            ":cflute"=>$_POST['const_flute'],
                            ":vendorqty"=>$_POST['vendorqty'],
                            ":wdat"=>$wdat,
                            ":ldat"=>$ldat,
                            ":scoreline"=>$scoreline,
                            ":duedate"=>$duedate,
                            ":vendorremark"=>$_POST['vendorremark'],
                            ":iso"=>"",
                            ":squarem"=>$_POST['squaremeter'],
                            ":squareft"=>$_POST['squarefeet'],
                            ":siid",$_POST['const_siid'],
                            ":wasteqty"=>$_POST['wasteqty'],
                            ":thisprice"=>$_POST['thisprice']));

    $resultB->execute(array(":svid"=>$_POST['selectedVID']));
    $resultC->execute(array(":locationselect"=>$_POST['locationselect']));

    $pdo->commit();

 }catch(PDOException $e){
    $pdo->rollBack();
    die("<h1>ERROR" . $e);
 }

1 个答案:

答案 0 :(得分:4)

问题出在这里:

":siid",$_POST['const_siid'],
       ^--- should be "=>", not ","