db_last_insert_id

6 database.pgsql.inc db_last_insert_id($table, $field)
6 database.mysql-common.inc db_last_insert_id($table, $field)

Returns the last insert id.

Parameters

$table: The name of the table you inserted into.

$field: The name of the autoincrement field.

Related topics

91 functions call db_last_insert_id()

File

drupal/includes/database.mysql-common.inc, line 539
Functions shared between mysql and mysqli database engines.

Code

<?php
function db_last_insert_id($table, $field) {
  return db_result(db_query('SELECT LAST_INSERT_ID()'));
}
?>