Reputation: 2358
I got a basic simple query to get data from a table. It doesn't need any parameters so I want to use a basic PDO::Query
way.
I got this:
$items = $cmsDbh->query("SELECT * FROM `tbl1`");
Now this is my AJAX file, I want to return the data as a JSON object. I tried using:
echo json_encode($items);
But then I get a JSON object which contains the queryString
(the SELECT * FROM tbl1
).
I don't want to use PDO::Prepare
, is there another way of doing it?
Upvotes: 0
Views: 152
Reputation: 2358
Was stupid. Appearantly PDO::Query
returns a PDOStatement
object, so you can just use fetchAll
. Working code:
echo json_encode($items->fetchAll(PDO::FETCH_ASSOC))
Upvotes: 0