Data in JSON format is not shown

0

Hello, I have the following php code:

<?php

require("config_local.php"); //conexao com o banco de dados

$area = "eua";
$st = "ny";


$sql = $pdo->prepare("SELECT prop,old_no,emissao,area,country,e_name FROM table1 WHERE area = :area AND st= :st ");
$sql->bindValue(":area",$area,PDO::PARAM_STR);
$sql->bindValue(":st",$st,PDO::PARAM_STR);
$sql->execute();

$result = $sql->fetchAll();
$n = $sql->rowCount();


echo $n ; // mostra o numero correto
echo json_encode($result); // nao mostra nada, tela em branco

The problem is that when I try to run this query, it returns me the blank screen, but if I take one of the fields to show, I get the data correctly.

The question is, is there any kind of PHP limitation for displaying large amounts of data / fields in JSON format? If so, how could I dribble it? I need to show these and a few more fields ...

Thank you.

    
asked by anonymous 31.05.2016 / 04:14

1 answer

0

Oops, it was utf8 encoding error.

I decided to put the line in my connection class:

$pdo->query("SET NAMES utf8;");

Looking like this:

<?php
try{
 $pdo = new PDO("mysql:host=localhost;dbname=mydb","root","");
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $pdo->query("SET NAMES utf8;");
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}catch(PDOException $e){

 echo 'Falha ao conectar - ERROR:' . $e->getMessage();
}

Thank you!

    
31.05.2016 / 06:05