8.5.x database.inc db_next_id($existing_id = 0)
8.0.x database.inc db_next_id($existing_id = 0)
8.1.x database.inc db_next_id($existing_id = 0)
8.2.x database.inc db_next_id($existing_id = 0)
8.3.x database.inc db_next_id($existing_id = 0)
8.4.x database.inc db_next_id($existing_id = 0)
8.6.x database.inc db_next_id($existing_id = 0)
4.6.x database.pgsql.inc db_next_id($name)
4.6.x database.mysql.inc db_next_id($name)
4.7.x database.pgsql.inc db_next_id($name)
4.7.x database.mysqli.inc db_next_id($name)
4.7.x database.mysql.inc db_next_id($name)
5.x database.pgsql.inc db_next_id($name)
5.x database.mysqli.inc db_next_id($name)
5.x database.mysql.inc db_next_id($name)
7.x database.inc db_next_id($existing_id = 0)

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

int $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

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

Deprecated

as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call nextId() on it. For example, $injected_database->nextId($existing_id);

See also

\Drupal\Core\Database\Connection::nextId()

Related topics

2 calls to db_next_id()
batch_process in core/includes/form.inc
Processes the batch.
NextIdTest::testDbNextId in core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php
Tests that the sequences API works.

File

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

Code

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