Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LAST_INSERT_ID() how it works at multi-users environment

Tags:

php

mysql

check that question first:
Inserting an automatically generated index from a table into another table
I got that this function "LAST_INSERT_ID()" do the required
the question is: I'm using that in a php script, what if some user inserted data in "table1" and before he insert the "id" into "table2" another user inserted data into "table1"...then which "id" would the function retrieve for the first user, his id or the id of the second user "the last one"??
I wish to retrieve the "id" that the user himself "the first user" inserted, so if it doesn't achieve that how to do it??

like image 592
Ahmed Waheed Avatar asked Apr 29 '11 18:04

Ahmed Waheed


1 Answers

LAST_INSERT_ID() gives you the last autogenerated id on the connection you execute it on, it does not return the last insert id globally produced by the MySQL server.

like image 174
nos Avatar answered Nov 15 '22 06:11

nos