mysql_insert_id

int mysql_insert_id([mysql link connection]) 

Gets the AUTO_INCREMENT value (if any) generated by the last query.

Returns:

Integer

Description:

mysql_insert_id() returns the AUTO_INCREMENT value (if any) generated by the last query made by the script calling mysql_insert_id(). If the connection argument is not set, the last connection opened is used by default.

mysql_insert_id() only returns a value if the last query on the specified connection handle caused an AUTO_INCREMENT column to generate a value. If you want to get the last AUTO_INCREMENT value generated, use the MySQL function LAST_INSERT_ID(). For example:

echo @ mysql_result (mysql_query ('SELECT LAST_INSERT_ID()')); 

mysql_insert_id() also returns the value for the ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.