mysqli_insert_id: What if someone inserts another row just before I call this?

mysql, mysqli, php

Solution

`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.

Problem

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) 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()`? 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? Thanks for your time.

Original source