简体   繁体   中英

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?

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 (eg an auto-increment). If you are creating your own ID's it won't return this to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM