InnoDB 插入无提示地失败,当表是 MyISAM 时工作正常
我在 MySQL 5.0.77 中有一个 InnoDB 表,如下所示:
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;
我正在使用 PHP 和 PDO 来执行插入。执行代码时,插入会默默失败。但是,如果我将表从 InnoDB 更改为 MyISAM,一切都会正常。如果我通过 PHPMyAdmin 运行 InnoDB 插入,它就会工作。
我将我的问题归结为这段代码(我的数据库凭据是正确的,因为 MyISAM 工作正常):
$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();
是什么导致这段代码在 MyISAM 上工作正常,但在 InnoDB 上却默默失败?
非常感谢您的指导。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2 个想法:
2 ideas :