[RESOLVED] LAST_INSERT_ID() is it safe with multiple users
Lets say I had a big site and I wanted to use
SELECT LAST_INSERT_ID() FROM cars
Would this always give me the correct info, even if I have lots of people updating the database at the same time?
For instance, I have a table called cars that I am inserting into a car, but I also have to update a table cars_countries, so I have to know the ID of the last car I updated that happens just milliseconds before because I have a form that will insert into both tables.
Or is there a way to do some kind of cascade update when you have foreign keys that would automatically update cars_countries with the car_id and country_id?
High Energy Magic Dept.
You do not state what DBMS you are using, but at least for MySQL you should be OK, as the insert ID is on a per-connection basis. (All bets are off, though, if for some reason you are using persistent connections, such as via mysql_pconnect().)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)