orbitz
12-07-2006, 01:32 AM
Would the result of getting mysql_insert_id() of the last insert be unpredictable if there are many users insert data to the same table at about the same time?
Should I use Lock table or something like this to make sure that each user get his correct insert id?
Thanks!
mysql_query("LOCK TABLES users WRITE");
mysql_query("SET AUTOCOMMIT = 0");
$sql = "INSERT INTO `users` (`organization`,`title`) VALUES ('$organization','$title')";
mysql_query($sql) or die (mysql_error());
$last_inserted_id = mysql_insert_id();
mysql_query("COMMIT");
mysql_query("UNLOCK TABLES");
Should I use Lock table or something like this to make sure that each user get his correct insert id?
Thanks!
mysql_query("LOCK TABLES users WRITE");
mysql_query("SET AUTOCOMMIT = 0");
$sql = "INSERT INTO `users` (`organization`,`title`) VALUES ('$organization','$title')";
mysql_query($sql) or die (mysql_error());
$last_inserted_id = mysql_insert_id();
mysql_query("COMMIT");
mysql_query("UNLOCK TABLES");
