简体   繁体   English

MYSQL last_insert_id()和并发

[英]MYSQL last_insert_id() and concurrency

I have a simple MYSQL question. 我有一个简单的MYSQL问题。 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? 如果我在网页上运行INSERT QUERY之后立即创建包含LAST_INSERT_ID()的查询,该网页有许多并发用户访问执行INSERT操作的其他页面,那么LAST_INSERT_ID()的值是否会被掺杂/损坏?

No, it will return the insert id from the current connection. 不,它将从当前连接返回插入ID。 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). 还要注意,这只会返回生成的ID(例如自动增量)。 If you are creating your own ID's it won't return this to you. 如果您要创建自己的ID,则不会将此返回给您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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