我正在升级我的网站以使用PDO。大部分代码工作正常,但我有一个INSERT语句,我无法工作。它适用于我的本地服务器,但不在现场。我检查过表格结构,它们是相同的。PHP PDO INSERT与预处理语句不兼容
这是我的代码
try {
foreach ($unique_product_line_ids AS $key => $value) {
$query_insertSQL = "
INSERT INTO tblCarts (
date_created
, session_id
, product_line_id
, posted_by_id
, quantity
) VALUES (
:date_created
, :session_id
, :product_line_id
, :posted_by_id
, :quantity1
)
ON DUPLICATE KEY UPDATE quantity = :quantity2
";
$insertSQL = $conn->prepare($query_insertSQL);
$insertSQL->execute(array(
':date_created'=>$date_created
, ':session_id'=>$session_id
, ':product_line_id'=>$key
, ':posted_by_id'=>$_SESSION['member']['individual_id']
, ':quantity1'=>$value
, ':quantity2'=>$value
));
$rc_insertSQL = $insertSQL->rowCount();
// close connection
$insertSQL->closeCursor();
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
我在unique_product_line_ids阵列检查的价值观和他们存在的确定。我也尝试删除ON DUPLICATE KEY UPDATE行(及其相应的参数),但这没有什么区别。
我花了几个小时试图消除潜在的原因,并孤立问题没有成功。任何帮助或指针将非常感激地收到。
感谢
任何错误的错误?在现场安装PDO吗? – Sal00m 2014-08-27 09:52:36
只是'echo $ insertSQL-> errorInfo()' – Sal00m 2014-08-27 09:58:20