| 5 database.mysql.inc | db_next_id($name) |
| 5 database.pgsql.inc | db_next_id($name) |
| 5 database.mysqli.inc | db_next_id( |
| 7 database.inc | db_next_id($existing_id = 0) |
| 8 database.inc | db_next_id($existing_id = 0) |
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
File
- includes/
database.pgsql.inc, line 235 - Database interface code for PostgreSQL database servers.
Code
<?php
function db_next_id($name) {
$id = db_result(db_query("SELECT nextval('%s_seq')", db_prefix_tables($name)));
return $id;
}
?> Login or register to post comments
Comments
So this is not available at
So this is not available at all in version 6?
The sequence table is
The sequence table is deprecated in Drupal 6 - I believe.
New serial ids are returned by drupal_write_record in 6.x
Getting the ids for serial fields is done through drupal_write_record() in 6.x
The new ids are returned by the write call - see the drupal_write_record help for version 6 ( http://api.drupal.org/api/function/drupal_write_record/6 ) for more information.
In Drupal 7 the purpose of this call is different to 4/5, according to the notes, it's intended for cases where you can't use a serial field at all.
drupal 6
for drupal 6 you can use db_last_insert_id and add 1.