MySQL:LAST_INSERT_ID()返回0 [英] MySQL: LAST_INSERT_ID() returns 0
问题描述
我有这个测试表:
CREATE TABLE IF NOT EXISTS`test`(`id_huh` bigint )unsigned
NOT NULL AUTO_INCREMENT,`title` varchar(255)NOT NULL DEFAULT
'test',PRIMARY KEY(`id_huh`),KEY`id_huh`(`id_huh`))
ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 4;
<$ p $ p> INSERT INTO`test`(`id_huh`,`title`)VALUES(NULL,'test')
INSERT INTO`test`(`id_huh`,`title`)VALUES (0,'test')
INSERT INTO`test`(`title`)VALUES('test')
b $ b
并发出
SELECT LAST_INSERT_ID
,但查询总是会导致 0
。
PHP mysql_insert_id
和 PDO :: lastInsertId()
也没有结果。
我一直在玩这整天,不能让它工作。想法?
问题似乎在MySQL的phpmyadmin配置文件 PersistentConnections
设置为 FALSE
,每次发出查询时都会产生一个新的 CONNECTION_ID
> SELECT LAST_INSERT_ID()无效。
同时感谢dnagirl 寻求帮助
I've got this test table:
CREATE TABLE IF NOT EXISTS `test` ( `id_huh` bigint(10) unsigned
NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL DEFAULT
'test', PRIMARY KEY (`id_huh`), KEY `id_huh` (`id_huh`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
inserting using either of these three
INSERT INTO `test` (`id_huh`, `title`) VALUES (NULL, 'test')
INSERT INTO `test` (`id_huh`, `title`) VALUES (0, 'test')
INSERT INTO `test` (`title`) VALUES ('test')
and issuing
SELECT LAST_INSERT_ID();
but the query always results in 0
.
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?
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.
more info in the subsequent topic Every query creates a new CONNECTION_ID()
Also thanks dnagirl for help
这篇关于MySQL:LAST_INSERT_ID()返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!