|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-26 18:08 UTC] rasmus@php.net
[2009-12-26 18:10 UTC] michaelozeryansky at hotmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
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