function db_next_id

Retrieves a unique id.

Use this function if for some reason you can't use a serial field. Using a serial field is preferred, and InsertQuery::execute() returns the value of the last ID inserted.

Parameters

$existing_id: After a database import, it might be that the sequences table is behind, so by passing in a minimum ID, it can be assured that we never issue the same ID.

Return value

An integer number larger than any number returned before for this sequence.

Related topics

4 calls to db_next_id()
action_save in drupal/core/modules/action/action.module
Saves an action and its user-supplied parameter values to the database.
batch_process in drupal/core/includes/form.inc
Processes the batch.
NextIdTest::testDbNextId in drupal/core/modules/system/lib/Drupal/system/Tests/Database/NextIdTest.php
Tests that the sequences API works.
UserStorageController::save in drupal/core/modules/user/lib/Drupal/user/UserStorageController.php
Overrides Drupal\Core\Entity\DatabaseStorageController::save().

File

drupal/core/includes/database.inc, line 526
Core systems for the database layer.

Code

function db_next_id($existing_id = 0) {
  return Database::getConnection()
    ->nextId($existing_id);
}