SQL insert in taxonomy_index doesn't work I used the following code, but it doesn't work, and I get no errors. 

$query = db_insert('taxonomy_index')-&gt;fields(array('nid', 'tid', 'sticky', 'created'));
$query-&gt;values(array(
  'nid' =&gt; $node-&gt;nid,
  'tid' =&gt; 53,
  'sticky' =&gt; 0,
  'created' =&gt; time(),
));
$query-&gt;execute();

dvm($query);

if (!$query) {
  dvm($query);
}


The output of this code is the following.



$query = db_insert('taxonomy_index')
  -&gt;fields(array('nid' =&gt; 27, 'tid' =&gt; 53, 'sticky' =&gt; 0, 'created' =&gt; time()))
  -&gt;execute();

dvm($query);

if (!$query) {
  dvm($query);
}


This code doesn't output any error; dvm($query) outputs '0'.

$row = new stdClass();
$row-&gt;nid = 27;
$row-&gt;tid = 55;
$row-&gt;created = time();
drupal_write_record('taxonomy_index', $row);


This gives the same result of the previous code.

$arr[] = 55;

db_query('INSERT INTO {taxonomy_index} VALUES  (%d, %d, %d, %d)', 27, 55, 0, time());


It doesn't work; It outputs the following error message.


  Recoverable fatal error: Argument 2 passed to db_query() must be of the type array, integer given, called in D:\OpenServer\domains\boobon\sites\all\modules\backup_bike\backup_bike.module on line 214 and defined в функции db_query() (строка 2342 в файле D:\OpenServer\domains\boobon\includes\database\database.inc).


I have installed the Ubercart module.
I think in D7, you can not use db_query() for insert operations - db_query() can be used only for Select and you should use db_insert() for insert operation.

For your 1st code bloc, perhaps the db_insert() causes 1st row with blank values - since it expects fields and values for 1st row. The subsequent $query->values() adds a second row. This may explain the blank values in dvm().