MySQL Forums
Forum List  »  PHP

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!

Options: ReplyQuote


Subject
Written By
Posted
How to get last insert id safely?
December 05, 2007 07:49PM


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.