php - PDO 插入不起作用

标签 php mysql pdo

即使在阅读了 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/

相关文章:

php - PDO 未输出正确的行数

php - 实际有值时sql语句返回null

php - odbc_pconnect 有效,但 PDO 给出错误

php - Laravel 如何知道 Request::wantsJson 是对 JSON 的请求?

PHP - 如何在我的数据库中的 4 个项目之间放置横幅

php - 扩展 PDO 类

php - AJAX 表单提交错误

php - 如何推送到 php 中的多维数组?

mysql - 当一个表的主键与另一个表的主键不同但包含在另一个表的主键中时,如何连接表?

mysql - 配置 Grails 应用程序以在 Heroku 上使用 ClearDB/MySQL