mysql_insert_id问题在并发数据插入 [英] mysql_insert_id issue in concurrency data inserting

查看:478
本文介绍了mysql_insert_id问题在并发数据插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在竞争条件下 mysql_insert_id()的可靠性如何?我的意思是当多个用户同时插入数据时,此函数将返回真实ID还是将返回其他用户插入的数据ID?

How reliable is mysql_insert_id() in a competitive condition? I mean when multiple users are inserting data at the same time, will this function return the true ID or it will return other user's inserted data ID?

表引擎是MyISAM 。

The table engine is MyISAM.

推荐答案

mysql_insert_id 完全是多用户安全。依赖于数据库连接,每个连接只能有一个用户....所以,根据你的问题,它返回true id ....

mysql_insert_id is completely multi-user safe.It is entirely relies upon the database connection, and you can only have one user per connection....So, as per your question, it returns true id....

MySql文档


生成的ID在服务器中以每个连接
的形式维护。这意味着
函数返回给给定客户端的值是第一个AUTO_INCREMENT值生成的
,用于影响该
客户端的AUTO_INCREMENT列的最近语句。此值不能受其他客户端影响,即使他们
生成自己的AUTO_INCREMENT值。此行为确保
每个客户端可以检索其自己的ID,而不需要关心其他客户端的
活动,也不需要锁或
事务。

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.

这篇关于mysql_insert_id问题在并发数据插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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