Reputation: 103
What would mysql_insert_id()
return in case some other query was made in the meantime? For example:
mysql_query('SOME INSERT1');
In the meantime, the other instance of this script calls mysql_query('SOME INSERT2');
, and in 1st instance:
echo mysql_insert_id();
Will this return the id of the first or the second insert?
Upvotes: 1
Views: 1444
Reputation: 20997
Each instance uses it's own connection and own connection identification, so the threads shouldn't be interfering and function should return insert id from last query.
Upvotes: 1
Reputation: 14638
It will return insert ID for your database connection session.
Please read this :
http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
and this:
Concurrency Problem With MySql Last_Insert_Id()... (C#)
Upvotes: 0
Reputation: 2581
mysql_insert_id
will return the id of the last inserted row. If you need to get the last insert id then make sure you do it before any other inserts are done on that table
Upvotes: 0
Reputation: 18531
Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).
Note:
Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value.
Upvotes: 0