mysql_insert_id

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

mysql_insert_id

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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."
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ahha thank you very much.
Post Reply