mysqli_insert_id:如果有人在我调用它之前插入另一行怎么办?

时间:2023-03-05
本文介绍了mysqli_insert_id:如果有人在我调用它之前插入另一行怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的问题很简单.我读过,检索我插入到 mysqli 中的行的 auto_increment/id 值的推荐方法是 mysqli_insert_id() 函数.但是,我不太熟悉,有一个问题:(此时这都是理论上的)

My question is a rather simple one. I've read that the recommended method of retrieving the auto_increment/id value of a row I've inserted in mysqli is the mysqli_insert_id() function. However, I'm not too familiar and had a question: (This is all theoretical at this point)

出于这些目的(因此是 mysqli 位),这一切都将来自 PHP Web 应用程序.假设多个用户同时在应用程序上,并且在我插入我的行和我调用 mysqli_insert_id() 的时间之间从不同的页面插入另一行?

For these purposes (hence the mysqli bit) this is all going to be from a PHP web application. Say multiple users are on the application at once and another row is inserted from a different page between the time that I insert my row and the time that I call mysqli_insert_id()?

这会返回错误的值,还是 MySQL 有某种功能可以防止这种情况发生?还是我只是高估了这种情况的可能性?

Would that return an incorrect value, or does MySQL have some sort of feature to prevent such a thing? Or am I simply overestimating the possibility of such a scenario?

感谢您的时间.

推荐答案

mysqli_insert_id() 特定于数据库连接——它返回this 最近插入的脚本调用,不是任何其他 MySQL 客户端.因此,如果多个应用程序同时插入到数据库中,则不会发生冲突.

mysqli_insert_id() is specific to the database connection -- it returns the ID of the row that this script invocation inserted most recently, not any other MySQL client. So there's no conflict if multiple applications are inserting into the database at the same time.

这篇关于mysqli_insert_id:如果有人在我调用它之前插入另一行怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:PHP 错误 ->警告:mysqli_stmt::execute(): 无法获取 mysqli_stmt |警告: 下一篇:如何在mysqli中做mysql_fetch_assoc?

相关文章