List:General Discussion« Previous MessageNext Message »
From:Johan Höök Date:February 15 2005 10:37am
Subject:Re: last_insert_id
View as plain text  
Hi,
You can probably use "SELECT LAST_INSERT_ID()" which keeps
auto-increment values on a per connection basis.
See:
http://dev.mysql.com/doc/mysql/en/getting-unique-id.html

/Johan

mel list_php wrote:
> Hi!
> 
> I have a database where several users can connect and input data.
> 
> I managed to have my insert queries as atomic, but I was wondering about 
> one special case: I make one insert, and retrieve the last id inserted 
> by mysql because I need to update an other table with that id.
> 
> - if one user inserts and retrieves the id, but between both one other 
> has inserted something the id returned will be the right one?
> 
> - or do I have to lock my table, execute the query, retrieve the id, 
> unlock the table?
> 
> - is there a way to make an atomic query with this that would avoid me 
> to use locks?
> 
> Thanks a lot for any help,
> 
> Melissa
> 
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today! 
> http://www.msn.co.uk/messenger
> 
> 

Thread
last_insert_idmel list_php15 Feb
  • Re: last_insert_idJohan Höök15 Feb
  • Re: last_insert_idAlec.Cawley15 Feb
  • Re: last_insert_idPhilippe Poelvoorde15 Feb
    • Re: last_insert_idmel list_php15 Feb
    • Re: last_insert_idmel list_php15 Feb
    • Re: last_insert_idmel list_php15 Feb