Sunday, September 24, 2017 06:20 am EDT

An Example of Using db_query in Drupal 7

Bri's picture

If you are writing your own modules, there is a good chance you have used db_query quite a bit in the past. The database layer has been overhauled in Drupal 7, and as a result, the way you get query results has changed slightly. Here is an example to how you how it's used.

// Notice the place holders are now done using the same syntax as PDOs (:uid)
// Placeholders also don't need to be quoted anymore.
$uid = 1;
$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid', array(':uid' => $uid));
// Result is returned as a iterable object that returns a stdClass object on each iteration

foreach ($result as $record) {
  // Perform operations on $record->title, etc. here.
  // in this example the available data would be mapped to object properties:
  // $record->nid, $record->title, $record->created
}

Comments

Anonymous's picture

боевой кастет

[url=http://kung-fu-ru.com/index.php?productID=1100]брелок кастет[/url] - купить кастет, фонарь дубинка.

Anonymous's picture

Getting solution of your

Getting solution of your problem is not difficult nowadays. The number of online education services is providing the best teaching and solutions of the problems. You can avail paper writer online help from experts related to any topic.

Anonymous's picture

Производственная СВ компания "Триада" предлагает

Изготовление светодиодных табло для спорта, бегущих строк, табло для АЗС. [url=http://ledbegorod.ru]ledbelgorod.ru[/url]

Anonymous's picture

Руслан Капов

[url=https://www.youtube.com/watch?v=gMeoQVJPNyY target="_blank" ]https://www.youtube.com/watch?v=9KI0c56_2No[/url]

Anonymous's picture

Thanks

Thanks

Anonymous's picture

Saved by this same blog post

Saved by this same blog post once again...

Anonymous's picture

Senthil

Useful information. Thanks.