I am doing a simple insert query using the db_insert call and no matter where I try this I am getting the same result, is this an error with the Drupal 7 DAL or am I doing something wrong?
The script is not running multiple times or the query is not being run multiple times; I am using the following in a custom PHP file to generate the data.
chdir('../');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$query = db_insert("table_name")
->fields(array('nid' => 10, 'width' => 200, 'height' => 800))
->execute();
I want to insert one record with the following data.
- nid: 10
- width: 200
- height: 800
Running this always without fail results in 2 exact records in the database. Has anyone else experienced this, or is it just me doing something wrong?
Could it be anything to do with not currently having the table I am inserting into inside my modules .install file? Maybe Drupal is doing something daft because it can't find the database schema info?
Any help would be appreciated.
Update
I seemed to have solved this issue by only bootstrapping Drupal with drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE)
instead of drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL)
. It must have something to do with the recursive bit in the bootstrap process. All is working fine now, so helping this helps anyone else who may be having issues like this.