Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for mysqli_insert_id to return an incorrect id in high traffic applications?

In a high traffic application, is it possible for mysqli_insert_id() to return the wrong id, or to confuse the id between two INSERT queries performed nearly simultaneously?

like image 525
Art Ianuzzi Avatar asked Feb 16 '12 16:02

Art Ianuzzi


People also ask

What is mysqli_ insert_ id?

The mysqli_insert_id() function returns the id (generated with AUTO_INCREMENT) from the last query.

What is insertid?

Return Values PHP mysqli_insert_id() function returns the value of the "Auto Increment" column in the last query In case it is INSERT or, UPDATE operation. If the last executed query is not INSERT or, UPDATE or, if the table doesn't have any column/field with "AUTO_INCREMENT" attribute, this function returns 0.


2 Answers

No. mysqli_insert_id returns the most the AUTO_INCREMENT value from the most recent INSERT query on the current connection. It will never get confused with another connection, for example.

like image 144
Niet the Dark Absol Avatar answered Sep 19 '22 10:09

Niet the Dark Absol


No. How can I be so sure? Because it would have been reported and fixed a long time ago.

like image 22
Ignacio Vazquez-Abrams Avatar answered Sep 19 '22 10:09

Ignacio Vazquez-Abrams