With the mysql_insert_id function, when the wrong process is: a page inserted a, id=1,b page inserted a bar, id=2,a page execution mysql_insert_id get the ID is 1 or 2?
Reply to discussion (solution)
A page of course is 1
A page of course is 1
Can I understand that it is the ID of the Inser statement that returns the previous step of the ' current page ', which is not very clear on W3school
If it is not 1, it will be troublesome, then write all the things, you have to worry about the problem of concurrency.
Queries can be sent to the MySQL server
mysql_query ("Select last_insert_id ()");
What if it's a 10,000 page? And what if it's an important transactional operation? Query the database more reliable
A mysql_insert_id Return of page A is 1
MySQL mysql_insert_id is for the MySQL process, for the server, mysql_query is an atomic operation, not Max (ID), even in the case of large concurrency does not appear inaccurate.
Can look at the MySQL
MYSQL_INSERT_ID is so defined.
My_ulonglong stdcall mysql_insert_id (MySQL *mysql)
{
Return mysql->;last_used_con->;insert_id;
}
The MySQL parameter is a struct that includes the database link and some status values for the current database link.
Where the insert_id,mysql_insert_id function inside the MySQL struct returns the value found inside the struct.
Must be 1, I can actually operate it, I understand