db_next_id
includes/database.pgsql.inc, line 235
- Versions
- 4.6 – 5
db_next_id($name)
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
Code
<?php
function db_next_id($name) {
$id = db_result(db_query("SELECT nextval('%s_seq')", db_prefix_tables($name)));
return $id;
}
?> 