"mel list_php" <list_php@stripped> wrote on 15/02/2005 10:18:55:
> 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
> special case: I make one insert, and retrieve the last id inserted by
> because I need to update an other table with that id.
> - if one user inserts and retrieves the id, but between both one other
> inserted something the id returned will be the right one?
> - or do I have to lock my table, execute the query, retrieve the id,
> the table?
> - is there a way to make an atomic query with this that would avoid me
> use locks?
last_insert_id is on a per-connection basis i.e. it gives the last id
inserted using that particular connection. Therefore you will always get
the most recent ID that you inserted, not the most recent that anyone
I think, therefore, that the natural behaviour is what you want.