gpt4 book ai didi

php - mysql_insert_id 使用安全吗?

转载 作者:行者123 更新时间:2023-11-29 22:01:38 24 4
gpt4 key购买 nike

根据 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/32589166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com