Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function db_next_id

Same name and namespace in other branches
  1. 8.9.x core/includes/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

$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

Database abstraction layer
Allow the use of different database servers using the same code base.
4 calls to db_next_id()
actions_save in includes/actions.inc
Saves an action and its user-supplied parameter values to the database.
batch_process in includes/form.inc
Processes the batch.
DatabaseNextIdCase::testDbNextId in modules/simpletest/tests/database_test.test
Test that the sequences API work.
user_save in modules/user/user.module
Save changes to a user account or add a new user.

File

includes/database/database.inc, line 2773

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.