last record ID

I am inserting record then getting the id using mysql_insert_id() from an auto increment field.

Will it always pull up the last id, entered by that user, or if another user add something,  is there a risk it could pull up the id for their record?

Who is Participating?
MySQL reference -

For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.
It will always be for the user session, irrespective of what other users do.  It is stored specific to the user session, in other words.
debbieau1Author Commented:
Thanks, that's a great help

Can I confirm that in my case last_insert_id() would be better to use.  I am not clear on the difference.

Also I did read somewhere that using mysql_insert_id() is a time bomb for very large tables.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.