站长网 MySql教程 php – mysql_insert_id可以安全使用吗?

php – mysql_insert_id可以安全使用吗?

根据PHP文档,mysql_insert_id从mysql表中获取最后一个插入的id. 我的问题是,如果我有一个每秒向数据库插入超过2行的网站,我可以使用mysql_insert_id并获取我之前在INSERT查询中引用的正确ID吗? 最佳答案从MySQL手册: The ID that was generated is maint

根据PHP文档,mysql_insert_id从mysql表中获取最后一个插入的id.

我的问题是,如果我有一个每秒向数据库插入超过2行的网站,我可以使用mysql_insert_id并获取我之前在INSERT查询中引用的正确ID吗?

最佳答案
从MySQL手册:

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.

简短版:使用安全.

本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/jc/mysql/2021/0524/6061.html

作者: dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。
联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部