php - mysql_insert_id 使用安全吗?

标签 php mysql

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

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

最佳答案

来自 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.

精简版:使用安全。

关于php - mysql_insert_id 使用安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069806/

相关文章:

php - Symfony2 "This authentication method requires a session"登录检查错误

php - 如何在 mysql 中加入这 5 个表?

php - MySQL:JOIN 和条件语句

c# - 我可以使用什么来进行本地 MySQL 测试?

mysql - 使用 UPDATE JOIN 和数据库参数

php - 如何运行 mysqli 查询?

php - MySQL 和 MSSQL 中用于 IF INSERT ELSE UPDATE 的常用语法

php - 无法弄清楚如何在 Laravel 上设置数据库

php - 如何在 elasticsearch 中使用 Unicode 字符进行搜索?

php - 实体上的 MySQL Double 多对多