@Peter

I thought there was something like that. Thanks for the clarification :)


On Wed, Jan 19, 2011 at 3:19 PM, Peter Karunyu <pkarunyu@gmail.com> wrote:
On Wed, Jan 19, 2011 at 2:42 PM, James Nzomo <kazikubwa@gmail.com> wrote:
That would work for a single user scenario...
But what happens when multiple users are doing the same thing almost simultaneously???

James, last_insert_id() uses the same connection used by the most recent INSERT, and since each user has a unique connection identifier, there is no way where the fkey returned by last_insert_id() will be the same for two different users.

Therefore, there will be no need to lock the tables.

http://dev.mysql.com/doc/refman/5.1/en/getting-unique-id.html

For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.

_______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------
Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke



--
Regards

Brian Ngure