Skip to content

Instantly share code, notes, and snippets.

@dergachev
Created February 1, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dergachev/1719517 to your computer and use it in GitHub Desktop.
Save dergachev/1719517 to your computer and use it in GitHub Desktop.
<?php
// 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 an 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
drupal_set_message("NID: $record->nid TITLE: $record->title CREATED: $record->created");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment