db_last_insert_id

Definition

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

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.

Code

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

Drupal is a registered trademark of Dries Buytaert.