You are here

function db_next_id in Drupal 5

Same name in this branch
  1. 5 includes/database.mysqli.inc \db_next_id()
  2. 5 includes/database.mysql.inc \db_next_id()
  3. 5 includes/database.pgsql.inc \db_next_id()
Same name and namespace in other branches
  1. 8 core/includes/database.inc \db_next_id()
  2. 4 includes/database.mysqli.inc \db_next_id()
  3. 4 includes/database.mysql.inc \db_next_id()
  4. 4 includes/database.pgsql.inc \db_next_id()
  5. 7 includes/database/database.inc \db_next_id()

Return a new unique ID in the given sequence.

For compatibility reasons, Drupal does not use auto-numbered fields in its database tables. Instead, this function is used to return a new unique ID of the type requested. If necessary, a new sequence with the given name will be created.

Note that the table name should be in curly brackets to preserve compatibility with table prefixes. For example, db_next_id('{node}_nid');

Related topics

14 calls to db_next_id()
aggregator_save_category in modules/aggregator/aggregator.module
Add/edit/delete aggregator categories.
aggregator_save_feed in modules/aggregator/aggregator.module
Add/edit/delete an aggregator feed.
aggregator_save_item in modules/aggregator/aggregator.module
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
drupal_client_ping in modules/drupal/drupal.module
Callback function from drupal_xmlrpc() called when another site pings this one.

... See full list

File

includes/database.mysqli.inc, line 245
Database interface code for MySQL database servers using the mysqli client libraries. mysqli is included in PHP 5 by default and allows developers to use the advanced features of MySQL 4.1.x, 5.0.x and beyond.

Code

function db_next_id($name) {
  $name = db_prefix_tables($name);
  db_query('LOCK TABLES {sequences} WRITE');
  $id = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $name)) + 1;
  db_query("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $id);
  db_query('UNLOCK TABLES');
  return $id;
}