InnoDB 插入无提示地失败,当表是 MyISAM 时工作正常

发布于 2024-11-09 11:45:46 字数 1307 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-11-16 11:45:46

2 个想法:

  • 您忘记提交事务。
  • 您的持久连接处于未确定状态

2 ideas :

  • You forgot to COMMIT the transaction.
  • Your persistent connection is in an undetermined state
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文