How to get last insert id safely?

From: Date: Thu, 06 Dec 2007 02:04:12 +0000
Subject: How to get last insert id safely?
Groups: php.db 
Request: Send a blank email to php-db+get-44393@lists.php.net to get a copy of this message
Hi All, 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! Regards Jacky

« previous php.db (#44393) next »