Maybe mysql_insert_id () will return an unexpected identifier

Maybe my question is stupid, but there is one thing I want to know about mysql_insert_id(). The following is written on php.net:

Gets the identifier generated for the AUTO_INCREMENT column by the previous query (usually INSERT).

What will this this function output if earlier the script reaches the line where mysql_insert_id()another script is used, inserts something into the database?

As far as I know, it will return the identifier of the last inserted element (it doesn't matter where it came from). If I'm right, I want to know how to avoid this problem, but with the help mysql_insert_id()immediately after the execution of the insert request (because there is still a small chance to get into the "problem").

+3
source share
1

id , ​​ , . .

MySQL. , , mysql_connect(). , , mysql_connect() . , E_WARNING .

,

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());

( AUTO_INCREMENT, ), . , , .

+3

All Articles