mysqli_insert_id:如果有人在我打电话之前插入另一行怎么办? [英] mysqli_insert_id: What if someone inserts another row just before I call this?

查看:118
本文介绍了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 脚本调用最近插入的行的ID,没有其他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:如果有人在我打电话之前插入另一行怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆