Questions about getting the ID of the SQL statement for the previous insert
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?
------to solve the idea----------------------
A page of course is 1
------to solve the idea----------------------
If it is not 1, it will be troublesome, then write all the things, you have to worry about the problem of concurrency.
------to solve the idea----------------------
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
------to solve the idea----------------------
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.
------to solve the idea----------------------
Must be 1, I can actually operate it, I understand