开发者

InnoDB insert fails silently, works fine when table is MyISAM

开发者 https://www.devze.com 2023-03-08 13:50 出处:网络
I\'ve got an InnoDB table in MySQL 5.0.77 that looks like this: CREATE TABLE `products_vendors` ( `vendor_id` int(10) unsigned NOT NULL,

I've got an InnoDB table in MySQL 5.0.77 that looks like this:

CREATE TABLE `products_vendors` (
`vendor_id` int(10) unsigned NOT NULL,
`product_id` int(10) unsigned NOT NULL,
`original_quantity` smallint(6) unsigned NOT NULL,
`quantity` smallint(5) unsigned NOT NULL,
`price` decimal(19,8) NOT NULL,
`created` int(10) unsigned NOT NULL,
`valid_until` int(10) unsigned NOT NULL,
PRIMARY KEY  (`vendor_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I'm using PHP and PDO to perform an insert. When the code is executed, the insert fails silently. But, if I change the table from InnoDB to MyISAM, e开发者_如何学运维verything works fine. The InnoDB insert works if I run it through PHPMyAdmin.

I've boiled my problem down to this piece of code (my db credentials are correct as the MyISAM works fine):

$insert_sql = "insert into products_vendors (";
$insert_sql.= "`vendor_id`,";
$insert_sql.= "`product_id`,";
$insert_sql.= "`original_quantity`,";
$insert_sql.= "`quantity`,";
$insert_sql.= "`price`,";
$insert_sql.= "`created`,";
$insert_sql.= "`valid_until` ";
$insert_sql.= ") values (";
$insert_sql.= "'1', '2', '3', '4', '5', '6', '7');";

$db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD, array(PDO::ATTR_PERSISTENT, true));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$st = $db->prepare($insert_sql);
$st->execute();

What would account for this code working fine with MyISAM but failing silently for InnoDB?

Many thanks for any guidance.


2 ideas :

  • You forgot to COMMIT the transaction.
  • Your persistent connection is in an undetermined state
0

精彩评论

暂无评论...
验证码 换一张
取 消