Page 1 of 1

mysql_insert_id

Posted: Fri Mar 24, 2006 7:21 pm
by shiznatix
ok So I have a lot of code that will validate inserted information and then insert it to the database. I am going to use mysql_insert_id() to get my infomation but I dont know much about it. I was wondering if maybe this function would return a ID that was old.

This is to say mabybe 2 or more people inserted somthing at the exact same time. If they did, would this function still work? I need this function to be able to insert to serveral tables but I need to be sure that this ID is correct without any ability of failure. Baically all I ask is...if I do a insert then do a mysql_insert_id() call is it possible to get invalid information?

Posted: Mon Mar 27, 2006 2:09 am
by JayBird
its all in the manual ;)
"The last ID that was generated is maintained in the server on a per-connection basis. This means the value the function returns to a given client is the most recent AUTO_INCREMENT value generated by that client. The value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that you can retrieve your own ID without concern for the activity of other clients, and without the need for locks or transactions."

Posted: Mon Mar 27, 2006 3:39 am
by shiznatix
ahha thank you very much.