1

I'm selecting all data from a table using fetchAll() via PDO from an MSSQL DB. I'm simply trying to do a json_encode on the results however when I do a json_encode I get a blank page when using an echo to display the results. I can do a var dump on the same array that I'm trying to encode and get all the data. I get no errors in the php logs and doing a json_last_error gives me NOTHING. Perhaps someone can see something in the following code that I'm not.

$sth = $db->prepare("SELECT * FROM dbo.Devices");
$sth->execute();
$result = $sth->fetchAll();

//var_dump($result);
echo json_encode($result);

I've also tried doing a utf8_encode on the data before passing it to the json_encode thinking that it was a character encoding issue and that was well gives me a blank page with no error message.

EDIT:

If I grab one row using fetch vs fetchAll it coverts the data fine.

So this works:

$result = $sth->fetch(PDO::FETCH_ASSOC);

But this doesn't:

$result = $sth->fetchAll(PDO::FETCH_ASSOC);
Cody J. Mathis
  • 652
  • 1
  • 9
  • 25

0 Answers0