I’m inserting a row in the users table to register a new user. I want to get the user_id field (which is Auto Increment) and user it in another queries. A solution is provided in here:
How to get the ID of INSERTed row in mysql? but I wonder what will happen if another user gets registered right after I insert a new row, and before I run the mysql_insert_id() function in my php code. What will the function return?
I’m inserting a row in the users table to register a new user. I
Share
mysql_insert_id()returns theauto_incrementid specific to the current connection (which is specific to the user session). So, it’s safe from that type of race condition. In other words, two concurrently connected users whose inserts overlap one another will always get back the correct ids for their own sessions without interference.