How to get last insert id safely?
Posted by:
Jacky Chan
Date: December 05, 2007 07:49PM
How to get last insert id safely in php with persistent connection to mysql?because there may be larger concurrence requests to the php to query insert statements.Example,the php query following two sql statements:
mysql_query("insert into tb(id,name) values(null,$username)");
$res = mysql_query("select last_insert_id()");
And in any time,user A insert one row to the table tb,and the same time before user A query last_insert_id(),user B insert another row to the same table too.
In this situation,will user A or B query last_insert_id() function get the correct id for he/her just insert?
Any ideas?Thanks!
Subject
Written By
Posted
How to get last insert id safely?
December 05, 2007 07:49PM
December 05, 2007 08:16PM
December 05, 2007 08:50PM
December 05, 2007 09:25PM
December 05, 2007 09:46PM
December 06, 2007 03:05AM
December 27, 2008 10:58AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.