PDO SQL 不会添加新条目
PDO SQL won't add new entries
没有显示错误,但由于某些原因,当我 运行 此脚本时无法添加新条目。任何帮助将不胜感激。
$sth = $dbh->prepare('INSERT INTO inventory(sku, product-id, product-id-type, price, minimum-seller-allowed-price, maximum-seller-allowed-price, item-condition, quantity, add-delete, will-ship-internationally, expedited-shipping, item-note, fulfillment-center-id)
VALUES(:sku, :product_id, :product_id_type, :price, :minimum, :maximum, :condition, :quantity, :add_delete, :international, :expedited, :note, :fulfillment)');
$sth->bindParam(':sku', $sku);
$sth->bindParam(':product_id', $product_id);
$sth->bindParam(':product_id_type', $product_id_type);
$sth->bindParam(':price', $price);
$sth->bindParam(':minimum', $minimum);
$sth->bindParam(':maximum', $maximum);
$sth->bindParam(':condition', $condition);
$sth->bindParam(':quantity', $quantity);
$sth->bindParam(':add_delete', $add_delete);
$sth->bindParam(':international', $international);
$sth->bindParam(':expedited', $expedited);
$sth->bindParam(':note', $note);
$sth->bindParam(':fulfillment', $fulfillment);
$sth->execute();
"No error is showing..."
没有错误?因为,您没有检查它们。您的许多专栏都包含连字符,并且 MySQL 认为您想进行数学运算。
即:product-id
其中 MySQL 翻译为 "product minus id" 等
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
会发出语法错误的信号。
用刻度线将所有包含连字符的列括起来。
(sku, `product-id`, `product-id-type` ...
等等
- 连接打开后立即添加
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
。
备注:
- 您应该尽量避免使用连字符作为单词分隔符,而是使用下划线。
这样你就不必使用刻度。
添加到这里是因为我无法在评论中正确编码。这不是问题的答案,但我怀疑会直接导致它。
像这样修改你的代码。
try {
// All $sth lines above in this section.
} catch (PDOException $e) {
// this will print an exception out if there is one.
echo $e->getMessage();
}
没有显示错误,但由于某些原因,当我 运行 此脚本时无法添加新条目。任何帮助将不胜感激。
$sth = $dbh->prepare('INSERT INTO inventory(sku, product-id, product-id-type, price, minimum-seller-allowed-price, maximum-seller-allowed-price, item-condition, quantity, add-delete, will-ship-internationally, expedited-shipping, item-note, fulfillment-center-id)
VALUES(:sku, :product_id, :product_id_type, :price, :minimum, :maximum, :condition, :quantity, :add_delete, :international, :expedited, :note, :fulfillment)');
$sth->bindParam(':sku', $sku);
$sth->bindParam(':product_id', $product_id);
$sth->bindParam(':product_id_type', $product_id_type);
$sth->bindParam(':price', $price);
$sth->bindParam(':minimum', $minimum);
$sth->bindParam(':maximum', $maximum);
$sth->bindParam(':condition', $condition);
$sth->bindParam(':quantity', $quantity);
$sth->bindParam(':add_delete', $add_delete);
$sth->bindParam(':international', $international);
$sth->bindParam(':expedited', $expedited);
$sth->bindParam(':note', $note);
$sth->bindParam(':fulfillment', $fulfillment);
$sth->execute();
"No error is showing..."
没有错误?因为,您没有检查它们。您的许多专栏都包含连字符,并且 MySQL 认为您想进行数学运算。
即:product-id
其中 MySQL 翻译为 "product minus id" 等
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
会发出语法错误的信号。
用刻度线将所有包含连字符的列括起来。
(sku, `product-id`, `product-id-type` ...
等等
- 连接打开后立即添加
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
。
备注:
- 您应该尽量避免使用连字符作为单词分隔符,而是使用下划线。
这样你就不必使用刻度。
添加到这里是因为我无法在评论中正确编码。这不是问题的答案,但我怀疑会直接导致它。
像这样修改你的代码。
try {
// All $sth lines above in this section.
} catch (PDOException $e) {
// this will print an exception out if there is one.
echo $e->getMessage();
}