I need to get the auto-increment value of the last inserted record to use later in a script. I'm just wondering which is the better way to write the code below that would lock the table that will provide the auto-increment info. Or does it matter if I do the mysql_insert_id() inside or outside of the table locking?
mysql_query("LOCK TABLES tablename READ/WRITE");
mysql_query(INSERT INTO tablename (id,content) VALUES (NULL,'$content')";
$id = mysql_insert_id();
mysql_query("UNLOCK TABLES");
...rest of script
OR
mysql_query("LOCK TABLES tablename READ/WRITE");
mysql_query(INSERT INTO tablename (id,content) VALUES (NULL,'$content')";
mysql_query("UNLOCK TABLES");
$id = mysql_insert_id();
...rest of script