db_query() and db_select() don't return any value
$get_counter_info-&gt;execute()-&gt;fetchAll();


will execute the query...but what are you doing with the results, exactly? At the moment you're discarding them, instead you need to assign them to a variable.

$results = $get_counter_info-&gt;execute()-&gt;fetchAll();
foreach ($results as $result) {
  ...
}


Or at the very least actually use the return value from the execution:

foreach ($get_counter_info-&gt;execute()-&gt;fetchAll() as $result) {
  ...
}