I query my database using the following query API code, but Drupal tells me that the result is a non-object. I can't find any reason to it
in what situation does db_query return anything but?
The error:
Fatal error: Call to a member function execute() on a non-object
the code:
for ($counter = 1; $counter <= 12; $counter++) {
$query[$counter] = db_query("SELECT `foo` FROM `{bar}` WHERE DATE(FROM_UNIXTIME(`thing_$counter`)) = CURRENT_DATE");
$results = $query['$counter']->execute()
->fetchAll();
}
The SQL works and produced results when I ran it in PHPmyAdmin.
The answer in this exchange looked tantalizing:
$date = date_create();
$date_to_test_against = $date->format('U');
$query[$counter] = db_query("SELECT `foo` FROM `{bar}` WHERE `thing_$counter` = $date_to_test_against");
however that produced the same result, calling execute on a non-object.
I know I don't have enough experience with this API yet. Can someone please point me to what I'm missing?