1

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

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

dvm($query);

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

The output of this code is the following.

query result

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

dvm($query);

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

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

$row = new stdClass();
$row->nid = 27;
$row->tid = 55;
$row->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.

1

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().

0

Only thing I see here is that your db_query has to give you an error, because it's not well set :

db_query(
   'INSERT INTO {taxonomy_index} VALUES (%a, %b, %c, %d)',
   array(
     '%a' => 27,
     '%b' => 55,
     '%c' => 0,
     '%d' => time()
   )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.