API page: http://api.drupal.org/api/drupal/includes!database!database.inc/function...
Drupal version : 7.18
While trying to migrate from drupal_write_record() to db_insert() / db_update(), discovered that db_insert() returns a weird key instead of the last inserted key.
I have standard empty 'accesslog' table that never been used for the example.
$data['timestamp'] = REQUEST_TIME;
$id = db_insert('accesslog')->fields($data)->execute();
dsm($id, 'db_insert');
$data = new stdClass();
$data->timestamp = REQUEST_TIME;
drupal_write_record('accesslog', $data);
dsm($data->aid, 'drupal_write_record');
what we get:
$id = 43587111;
$data->aid = 2;
So you can see that drupal_write_record() returns the correct last id, while db_insert() returns some weird key.
@see screenshot attached
Comments
Comment #1
alechko commentedfixing version and component info
Comment #2
avpadernoBugs are always fixed in the development snapshot.
Comment #3
Erich Schulz commentedjust experienced this
I'm on mysql and core is uptodate
I'm inserting to a custom table without a schema definition - the record inserts ok