即使在阅读了 S.O 上的所有“PDO 插入不起作用”问题之后,我仍然无法弄清楚 PDO SQL 查询中什么不起作用。很乐意在这方面获得一些帮助。
$sql = "INSERT INTO `order_item` (`fk_order`,`fk_product`,`product_excl_tax`,`tax_product`,`shipping_excl_tax`,`tax_shipping`,`order_item_status`,`updated_at`)
VALUES (:theorderid, :product_id, :product_price, :price_incl_tax, :product_shipping, :product_shippingttc, :order_item_status, :dater) " ;
$req = $co_db->prepare($sql);
$req -> bindParam(':theorderid', $theorderid, PDO::PARAM_INT);
$req -> bindParam(':product_id', $product_id, PDO::PARAM_INT);
$req -> bindParam(':product_price', $product_price, PDO::PARAM_STR);
$req -> bindParam(':price_incl_tax', $price_incl_tax, PDO::PARAM_STR);
$req -> bindParam(':product_shipping', $product_shipping, PDO::PARAM_STR);
$req -> bindParam(':product_shippingttc', $product_shippingttc, PDO::PARAM_STR);
$req -> bindParam(':order_item_status', $thestatus , PDO::PARAM_INT);
$req -> bindParam(':dater', $thedate, PDO::PARAM_STR);
$req->execute();
最佳答案
感谢@RyanVincent,我将以下行添加到我的 PDO 连接对象声明中:
$co_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $co_db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
它让我看到我想要输入的数据与 MYSQL 中设置的限制之间存在错误。
关于php - PDO 插入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33858672/