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/31042509/

相关文章:

php - Laravel Ajax 响应和处理错误

php - 使用 PHP 的事件导航栏?

Phpunit - fatal error : require(): Failed opening required 'PHP\Invoker.php'

mysql - 按有序列分组

php - 使用 php 和 mysql 检索上个月插入的值

MySQL - 根据周/月数字获取 sum()

Java SQL 只显示正确的记录

php - 从 MySQL 中连续选择随机用户

javascript - 从另一台服务器安全地从 JS 发送到 PHP

php/mysql - while 循环..pass 结果在数组中?