db_last_insert_id($table, $field)
drupal/includes/database/database.inc, line 2353
Returns the last insert id.
@todo Remove this function when all queries have been ported to db_insert().
$table The name of the table you inserted into.
$field The name of the autoincrement field.
| Name | Description |
|---|---|
| Database abstraction layer | Allow the use of different database servers using the same code base. |
| Schema API | A 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. |
function db_last_insert_id($table, $field) {
$sequence_name = Database::getActiveConnection()->makeSequenceName($table, $field);
return Database::getActiveConnection()->lastInsertId($sequence_name);
}