I didn't find an exact answer so I try to ask here. I running an SQL INSERT Query and after that I want to use the ID of the this INSERT Query, I found this: LAST_INSERT_ID() and it's work, but I thinking what would happen if I not the only one who run the query on the server I can get a wrong ID from the DB, so there is other to take the last ID ?
It should return the last inserted row id from the same connection. So if other user has inserted another row in between, LAST_INSERT_ID function will still return the relevant idfor the first user.
Quoting from mysql documentation:
The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function(LAST_INSERT_ID) to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client
Here is the link http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id .
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments