function db_next_id in Drupal 8
Same name and namespace in other branches
- 4 includes/database.mysqli.inc \db_next_id()
- 4 includes/database.mysql.inc \db_next_id()
- 4 includes/database.pgsql.inc \db_next_id()
- 5 includes/database.mysqli.inc \db_next_id()
- 5 includes/database.mysql.inc \db_next_id()
- 5 includes/database.pgsql.inc \db_next_id()
- 7 includes/database/database.inc \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
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
in drupal:8.0.0 and is removed from 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
https://www.drupal.org/node/2993033
\Drupal\Core\Database\Connection::nextId()
Related topics
1 call to db_next_id()
- DatabaseLegacyTest::testDbNextId in core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php - Tests deprecation of the db_next_id() function.
File
- core/
includes/ database.inc, line 517 - Core systems for the database layer.
Code
function db_next_id($existing_id = 0) {
@trigger_error('db_next_id() is deprecated in drupal:8.0.0. It will be removed from 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 https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()
->nextId($existing_id);
}