[RESOLVED] LAST_INSERT_ID() is it safe with multiple users
Results 1 to 3 of 3

Thread: [RESOLVED] LAST_INSERT_ID() is it safe with multiple users

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    121

    resolved [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?

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,478
    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().)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    121
    thanks, i am using mysql

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •