pdo查询没有运行

时间:2014-10-18 04:03:00

标签: php mysql pdo

我似乎无法弄清楚为什么这个查询没有运行

if ( $productName && $productDescription && $productPrice ) {
// SQL
// UPDATE `prostud_tristurion`.`products` SET `product_title` = 'ajax test', `product_description` = 'Was certainty remaining engrossed applauded sir how discovery.', `product_price` = '524' WHERE `products`.`product_id` = 10;
try {

    $query = "update products set product_title = :pName, product_description = :pDescription, product_price = :pPrice, where product_id = :pid";
    //prepare query for excecution
    $stmt = $con->prepare($query);

    //bind the parameters
    $stmt->bindParam(':pid', $id);
    $stmt->bindParam(':pName', $productName);
    $stmt->bindParam(':pDescription', $productDescription);
    $stmt->bindParam(':pPrice', $productPrice);
    // echo "$productPrice / $productDescription / $productName / $id\n $stmt";
    var_dump($_POST);
    // Execute the query
    if ($stmt->execute() ) {
        echo "Record was updated.";
    } else {
        die('Unable to update record.');
    }

}catch(PDOException $exception){ //to handle error
    echo "Error: " . $exception->getMessage();
}
}

我得到的是无法更新记录。

var_dump($_POST); 

看起来不错

1 个答案:

答案 0 :(得分:4)

您在product_price = :pPrice, where

处有错误的逗号

如果您的代码到达die语句,则关闭异常(不推荐)但您可以使用$stmt->errorInfo()

从数据库中获取错误消息(记录或回显)