db_last_insert_id

Definition

db_last_insert_id($table, $field)
drupal/includes/database/database.inc, line 2353

Description

Returns the last insert id.

@todo Remove this function when all queries have been ported to db_insert().

Parameters

$table The name of the table you inserted into.

$field The name of the autoincrement field.

Related topics

Namesort iconDescription
Database abstraction layerAllow the use of different database servers using the same code base.
Schema APIA Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema(), which usually lives in a modulename.install file.

Code

function db_last_insert_id($table, $field) {
  $sequence_name = Database::getActiveConnection()->makeSequenceName($table, $field);
  return Database::getActiveConnection()->lastInsertId($sequence_name);
}