mysql SQL语法中的PDOException错误

时间:2014-07-27 14:26:45

标签: php mysql pdo

我的数据库中有以下2个插入,代码如下:

$sql1 = "INSERT INTO order(order_id,user_id,product_id,sku,product_name,currency,price,quantity,options,value) VALUES (:orderid,:userid,:productid,:sku,:productname,:currency,:price,:quantity,:options,:value)";                                          
    $stmt1 = $conn->prepare($sql1);
    for($i=0; $i < $count; $i++) {
    //options
    $options = array();
    if(isset($_SESSION['color'.$i]) && !empty($_SESSION['color'.$i])) {array_push($options, $_SESSION['color'.$i]);}
    if(isset($_SESSION['density'.$i]) && !empty($_SESSION['density'.$i])) {array_push($options, $_SESSION['density'.$i]);}
    if(isset($_SESSION['diameter'.$i]) && !empty($_SESSION['diameter'.$i])) {array_push($options, $_SESSION['diameter'.$i]);}
    if(isset($_SESSION['flavor'.$i]) && !empty($_SESSION['flavor'.$i])) {array_push($options, $_SESSION['flavor'.$i]);}
    if(isset($_SESSION['holepitch'.$i]) && !empty($_SESSION['holepitch'.$i])) {array_push($options, $_SESSION['holepitch'.$i]);}
    if(isset($_SESSION['size'.$i]) && !empty($_SESSION['size'.$i])) {array_push($options, $_SESSION['size'.$i]);}

    $stmt1->bindParam(':orderid', $ordernumber, PDO::PARAM_STR);      
    $stmt1->bindParam(':userid', $UserID, PDO::PARAM_STR);
    $stmt1->bindParam(':productid',  $_SESSION['pid'.$i], PDO::PARAM_STR);
    $stmt1->bindParam(':sku', $_SESSION['sku'.$i], PDO::PARAM_STR);
    $stmt1->bindParam(':productname',$_SESSION['itemname'.$i], PDO::PARAM_STR); 
    $stmt1->bindParam(':currency',$currency, PDO::PARAM_STR);   
    $stmt1->bindParam(':price', $_SESSION['price'.$i], PDO::PARAM_STR);  
    $stmt1->bindParam(':quantity', $_SESSION['quantity'.$i], PDO::PARAM_STR);  
    $stmt1->bindParam(':options', $options[0], PDO::PARAM_STR);   
    $stmt1->bindValue(':value', $_SESSION['quantity'.$i] * $_SESSION['price'.$i], PDO::PARAM_STR);                             
    $stmt1->execute(); 


    //insert 2

    $sql2 = "INSERT INTO shipping_cost(order_id,shipping_option,shipping_cost ) VALUES (:orderid,:shippingoption,:shippingcost)";                                          
    $stmt2 = $conn->prepare($sql2);                                         
    $stmt2->bindParam(':orderid', $ordernumber, PDO::PARAM_STR);     
    $stmt2->bindParam(':shippingoption', $shippingoption, PDO::PARAM_STR);     
    $stmt2->bindParam(':shippingcost', $shippingcost, PDO::PARAM_STR);                               
    $stmt->execute(); 
    } //end for

上述查询导致以下PDOException并显示消息:

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'order(order_id,user_id,product_id,sku,product_name,currency,price,quantity,optio'在第1行'附近使用正确的语法

我无法理解上面的PDO声明有什么问题。

请求帮助。提前谢谢。

0 个答案:

没有答案