MySQL:LAST_INSERT_ID() 返回 0
我有这个测试表:
CREATE TABLE IF NOT EXISTS `test` (
`id` INT(10) AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4;
使用这三个中的任何一个插入
inserting using either of these three
INSERT INTO `test` (`id`) VALUES (NULL);
INSERT INTO `test` (`id`) VALUES (0);
INSERT INTO `test` () VALUES ();
和发行
SELECT LAST_INSERT_ID();
但查询结果总是0
.
PHP 的 mysql_insert_id
和 PDO::lastInsertId()
也没有结果.
PHP's mysql_insert_id
and PDO::lastInsertId()
yield no result either.
我一整天都在玩弄这件事,但无法让它发挥作用.想法?
I've been toying with this whole day and can't get it to work. Ideas?
推荐答案
问题似乎出在 MySQL 的 phpmyadmin 配置文件 PersistentConnections
设置为 FALSE
这导致了一个新的CONNECTION_ID
每次发出查询时 - 因此使 SELECT LAST_INSERT_ID()
无效.
The problem seemed to be in MySQL's phpmyadmin config file PersistentConnections
set to FALSE
which resulted in a new CONNECTION_ID
every time a query was issued - therefore rendering SELECT LAST_INSERT_ID()
ineffective.
后续主题中的更多信息每个查询都会创建一个新的 CONNECTION_ID()
同时感谢dnagirl的帮助
相关文章