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

查看:38
本文介绍了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_idPDO::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的帮助

这篇关于MySQL:LAST_INSERT_ID() 返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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