MySQL:LAST_INSERT_ID()返回0 [英] MySQL: LAST_INSERT_ID() returns 0

查看:857
本文介绍了MySQL:LAST_INSERT_ID()返回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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆