query API calling db_query result a non-object, but SQL works
In the case of db_query, what you get back from it is a resource (it is just a wrapper around php's mysql_query.

But the answer depends on if you're in Drupal 6 or 7

Drupal 6:

In order to turn that into an object, you need to run db_fetch_object on the result, and if you have multiple results you'd need to loop through it.

For example:

&lt;?php
    $sql = "SELECT buckles FROM foo WHERE llama = 'cheese'";
    $result = db_query($sql);

    while ($rowObj = db_fetch_object($result)) {
        echo $rowObj-&gt;buckles;
    }


Drupal 7

Use the nifty db_select api! The examples on that page pretty good, but basically it builds a query and then returns something that's very similar to a PDO object (see SelectQuery::execute for the following example)

&lt;?php
  $matches = array();
  $query = db_select('table')
     -&gt;fields('table', array('field_name'));

  foreach ($query-&gt;execute() as $row) {
     $matches[$row-&gt;relation_type] = $row-&gt;label;
  }