There was a question last week about the behavior of this function, which is inconsistently (and inaccurately) documented in the manual.

A little black box testing shows the following:

1) mysql_insert_id successfully retrieves the last
   auto_inserted id used by a connection.

2) multiple processes, each with their own connection
   will obtain the correct last-inserted-id for that
   connection. This is not table specific! It is the
   last autoinsert to take place.

3) the function will return the same auto_incremented
   id until a table with an auto_increment column is
   updated. ie: select queries and do NOT reset the
   id.

4) in the case of updates, the following behavior,
   in contrast to the documentation, is observed:

  A. Inserting a row into a table will reset mysql_insert_id
     whether you make use of auto_increment functionality
     or not. mysql_insert_id will be set to the new value
     even if you forced a new value in via sql. ie:

     insert into test (id, desc) values (NULL, 'test');
     mysql_insert_id will = 32 (or whatever the next value was).

     insert into test (id, desc) values (77, 'test;);
     mysql_insert_id will = 77.

  B. Updating a row with an auto_insert column will reset
     mysql_insert_id to 0.

Notes:

Version: 4.0.15 standard
Platform: Linux x86

-Blunt Jackson


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to