Phpmysql_insert_id () returns the Latest Database id implementation method. for details, refer to the code below: mysql_insert_id () function returns... php mysql_insert_id () returns the Latest Database id implementation method. for details, refer to the code below:
Mysql_insert_id ()
The mysql_insert_id () function returns the ID generated by the previous INSERT operation. If no AUTO_INCREMENT ID is generated in the previous query, mysql_insert_id () returns 0.
Syntax:Mysql_insert_id (connection)
The connection parameter (optional) specifies the MySQL connection. if not specified, the previous connection is used.
Mysql_insert_id () returns the AUTO_INCREMENT ID generated in the previous INSERT query in the given connection. If no connection is specified, the previous opened connection is used.
If you want to save the value and use it later, make sure that mysql_insert_id () is called immediately after the query that generates the value. The code is as follows:
Mysql_insert_id () returns the AUTO_INCREMENT ID generated in the previous INSERT query in the given link_identifier. if link_identifier is not specified, the previous opened connection is used, if the value of AUTO_INCREMENT is not generated in the previous query, mysql_insert_id () returns 0. if you want to save the value and use it later, make sure that mysql_insert_id () is called immediately after the query that generates the value ().
LAST_INSERT_ID ()
MySQL also provides an API with the same function. it always stores the newly generated AUTO_INCREMENT value and will not be reset between query statements. that is to say, after the INSERT operation is executed, executing SELECT, UPDATE, and DELETE statements does not affect the return values of this API.
You can use SELECT LAST_INSERT_ID (); to query the return value of LAST_INSERT_ID.
INSERT multiple records using a single INSERT statement. LAST_INSERT_ID () only returns the AUTO_INCREMENT value generated by the first inserted record.
Article address:
Reprint at will ^ please include the address of this article!