Home > PHP > Function > MySQL > mysql_insert_id()

mysql_insert_id()

mysql_insert_id - Get the ID generated in the last query

Syntax

int mysql_insert_id (resource $link_identifier)

Arguments

  • link_identifier - The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.

Description

Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).

Version

PHP 4, 5

Return value

The ID generated for an AUTO_INCREMENT column by the previous query on success, 0if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.