From: michaelozeryansky at hotmail dot com Operating system: Windows XP Pro SP 3 PHP version: 5.3.1 PHP Bug Type: MySQL related Bug description: mysql_insert_id not returning last inserted ID
Description: ------------ I have never used mysql_insert_id() before, but I think its not too hard to get right. From what I know it will return "The ID generated for an AUTO_INCREMENT column by the previous query on success" as stated on php.net/manual. When I run my insert query, which inserts multiple(10) rows, the mysql_insert_id only gives the 'first' id used and not the last id. In my code this is actually more useful to me, but I had to figure it out the hard way. Is this a bug or a feature? P.S. I'm using 5.3.0, but I checked and 5.3.1 doesn't mention this Reproduce code: --------------- $query = 'INSERT INTO player VALUES '; foreach($data['players'] as $player){ $query .= sprintf("(null, '%s', '%s', '%s', '%s', '%s', %s),", $stuff, $stuff, $stuff, $stuff, $stuff, $stuff); } $query = substr($query,0,-1);//removes last comma $result = mysql_query($query, $resource) or die(mysql_error()); $firstPlayerID = mysql_insert_id($resource); Expected result: ---------------- 10 players, starting at AUTO=1 result should be = 10 Actual result: -------------- 10 players, starting at AUTO=1 result is = 1 -- Edit bug report at http://bugs.php.net/?id=50580&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50580&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50580&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50580&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50580&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50580&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50580&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50580&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50580&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50580&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50580&r=support Expected behavior: http://bugs.php.net/fix.php?id=50580&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50580&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50580&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50580&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50580&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50580&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50580&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50580&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50580&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50580&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50580&r=mysqlcfg