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

mysqli_insert_id: What if someone inserts another row just before I call this?(mysqli_insert_id:如果有人在我调用它之前插入另一行怎么办?)
本文介绍了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:如果有人在我调用它之前插入另一行怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)