简体   繁体   中英

InnoDB insert fails silently, works fine when table is MyISAM

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, everything 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM