I am trying to debug why the below query does not return a result set. When I tried debugging this using print_r to see what this sql returns , i get the sql statement itself instead of the result set. Can someone help me with why this doesn’t return a result set ?
Edit: I am using query function of the PHP Data Objects
$query = "select * from categories order by categoryID";
$categories = $db->query($query);
print_r($categories);
Because that method returns a
PDOStatementobject, as stated in the manual, not an associative array. You have to get the resultset from this object first.You could use
fetchAll()to get all the results in an associative array (or any other PDO fetch method according to your taste):When you encounter problems like this, it is always advisable to read the manual.