[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().)
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)