Bug #49942 | In PHP mysql_insert_id() returns the wrong ID for multiple inserts in one query | ||
---|---|---|---|
Submitted: | 26 Dec 2009 18:24 | Modified: | 26 Dec 2009 18:44 |
Reporter: | Michael Ozeryansky | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S3 (Non-critical) |
Version: | OS: | Windows (XP Pro SP3) | |
Assigned to: | CPU Architecture: | Any | |
Tags: | id, insert, multiple, mysql_insert_id(), php |
[26 Dec 2009 18:24]
Michael Ozeryansky
[26 Dec 2009 18:39]
Valeriy Kravchuk
This is a feature. Please, read the manual, http://dev.mysql.com/doc/refman/5.1/en/mysql-insert-id.html: "In the case of a multiple-row INSERT statement, the return value of mysql_insert_id() depends on the MySQL server version. In MySQL 5.1.12 and later, mysql_insert_id() returns the first automatically generated AUTO_INCREMENT value that was successfully inserted. In MySQL 5.1.11 and earlier, mysql_insert_id() returns the first automatically generated AUTO_INCREMENT value, regardless of whether insertion of that value was successful."
[26 Dec 2009 18:44]
Michael Ozeryansky
Thank you. This is actually better for me, less math.