|
mysql_insert_idGet the ID generated in the last query Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
Description
int mysql_insert_id
([ resource
$link_identifier = NULL
] )Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). Parameters
Return Values
The ID generated for an AUTO_INCREMENT column by the previous
query on success, 0 if the previous
query does not generate an AUTO_INCREMENT value, or Examples
Example #1 mysql_insert_id example
<?php NotesCaution
mysql_insert_id will convert the return type of the native MySQL C API function mysql_insert_id() to a type of long (named int in PHP). If your AUTO_INCREMENT column has a column type of BIGINT (64 bits) the conversion may result in an incorrect value. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query. For more information about PHP's maximum integer values, please see the integer documentation.
See Also
|