【问题标题】:SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokensSQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配
【发布时间】:2012-07-15 05:39:10
【问题描述】:

我的代码产生了错误:

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);
 }

【问题讨论】:

  • 在每个单独的 execute() 周围包裹一个 try/catch,这样你至少可以找出你的 3 个查询中的哪一个导致了这种情况。
  • 我测试过,它的 $insert1

标签: sql pdo


【解决方案1】:

问题来了:

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

【讨论】:

    猜你喜欢
    • 2017-04-27
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    相关资源
    最近更新 更多