db_query not returning anything (or empty) - drupal 7 I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');


and if I do:

echo (string)$result-&gt;name;


nothing is displayed.

Does anyone know what could be causing this?

Edit - Updated with new code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$result = db_query('SELECT OFFICE_ID FROM {OFFICE}');
$counter = 0;
foreach($result as $record) {
  $counter = $counter + 1;
  print $record-&gt;office_id;
}
print $counter;


Nothing will be printed, but at the end of the loop, the number of loops performed is the same as the number of rows returned from a direct query on the DB itself.
The return from db_query() is a resource that you can iterate over, it's never a single value.

The way to get a single field from a query is with the fetchField() method:

$result = db_query('SELECT name FROM {users} WHERE uid = 1')-&gt;fetchField();


If you've got more than one result then you can iterate over it like so:

foreach ($result as $row) {
  // Do something with $row...
}


or, you can make use of one of the helper methods to get data directly from the query into a local variable. These include:


fetchObject()


  Fetches the next row and returns it as an object.

fetchAllAssoc()


  Returns the result set as an associative array keyed by the given field.

fetchAllKeyed()


  Returns the entire result set as a single associative array.

fetchAssoc()


  Fetches the next row and returns it as an associative array.

fetchCol()


  Returns an entire single column of a result set as an indexed array.

fetchField()


  Returns a single field from the next record of a result set.