thegalah
thegalah

Reputation: 528

MYSQL last_insert_id() and concurrency

I have a simple MYSQL question. If I make a query that contains LAST_INSERT_ID() right after an INSERT QUERY running on a web page which has many concurrent users accessing other pages that perform INSERT operations would the value of LAST_INSERT_ID() be adulterated/corrupted?

Upvotes: 23

Views: 6365

Answers (1)

charliefortune
charliefortune

Reputation: 3200

No, it will return the insert id from the current connection. As long as your script hasn't made any other inserts, you will get the one you want.

Also be aware that this will only return a generated ID (e.g. an auto-increment). If you are creating your own ID's it won't return this to you.

Upvotes: 28

Related Questions