PDO插入不运行bindParam bindValue

时间:2015-11-22 18:44:20

标签: php mysql pdo

即使在阅读了S.O上的所有'PDO Insert not working'问题之后,我仍然无法弄清楚在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();    

1 个答案:

答案 0 :(得分:1)

感谢@RyanVincent,我在PDO连接对象声明中添加了以下行:

$ co_db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION); $ co_db-> setAttribute(PDO :: ATTR_EMULATE_PREPARES,true);

它允许我看到我想输入的数据与MYSQL中设置的限制之间的错误。

相关问题