MYSQL last_insert_id()和并发 [英] MYSQL last_insert_id() and concurrency

查看:1261
本文介绍了MYSQL last_insert_id()和并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的MYSQL问题。如果在网页上运行 INSERT QUERY 之后,如果在网页上运行了许多并发用户访问执行 INSERT 的其他网页,则我立即进行包含 LAST_INSERT_ID()操作会使 LAST_INSERT_ID()的值被掺杂/损坏?

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?

推荐答案

将从当前连接返回insert id。

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.

还要注意,这只会返回一个生成的ID(例如自动递增)。如果您要创建自己的ID,则不会将此退回给您。

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.

这篇关于MYSQL last_insert_id()和并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆