Bug #2132 LAST_INSERT_ID()/mysql_insert_id() not in sync
Submitted: 16 Dec 2003 14:20 Modified: 2 Feb 2004 23:18
Reporter: Paul DuBois Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0/4.1 OS:
Assigned to: Bugs System CPU Architecture:Any

[16 Dec 2003 14:20] Paul DuBois
Description:
LAST_INSERT_ID() and mysql_insert_id() can get out
of sync under the following conditions.

Execute these statements:

USE test
DROP TABLE IF EXISTS t
CREATE TABLE t (i INT NOT NULL AUTO_INCREMENT PRIMARY KEY)
INSERT t SET i = NULL
SELECT LAST_INSERT_ID()
INSERT t SET i = 24
SELECT LAST_INSERT_ID()

After the first INSERT, LAST_INSERT_ID() and
mysql_insert_id() both are 1.

After the second INSERT, LAST_INSERT_ID()
remains 1, but mysql_insert_id() is 24.

Perhaps this is what is supposed to happen,
but I find it surprising/unexpected. I'm filing
it as a bug because I believe that the two
functions are supposed to return the same value
in most cases?

How to repeat:
See above.
[2 Feb 2004 23:18] Michael Widenius
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).