ID:               50580
 User updated by:  michaelozeryansky at hotmail dot com
 Reported By:      michaelozeryansky at hotmail dot com
-Status:           Wont fix
+Status:           Closed
 Bug Type:         MySQL related
 Operating System: Windows XP Pro SP 3
 PHP Version:      5.3.1
 New Comment:

Alright thanks, I wanted to ask PHP first just in case. 
I'm off to MySQL.


Previous Comments:
------------------------------------------------------------------------

[2009-12-26 18:08:57] ras...@php.net

Your argument is sound, but there isn't much we can do here.  The 
mysql_insert_id() function in PHP just calls the MySQL client library 
function of the same name.  We don't do anything at the PHP level here,

we simply give you what the Database and the client library pass back 
to us.  So, to pursue this you need to ask the MySQL folks.

------------------------------------------------------------------------

[2009-12-26 17:28:32] michaelozeryansky at hotmail dot com

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 this bug report at http://bugs.php.net/?id=50580&edit=1

Reply via email to