I'm using a PHP page to get some data in my MySQL Database, I was using an xml structure to do that, but since I found JSON a little faster I decided to migrate all my webserver to that.
I use exactly the same code to retrieve data from the database, but the generated JSON can't get all the data; some fields like Description
, and others like Nome
, sometimes come as a null object. In the database everything is okay, and the XML script is also still running okay.
Here's the PHP script I'm using:
<?php
header('Content-type: application/json');
$banco = "*******";
$usuario = "*******";
$senha = "*******";
$hostname = "localhost";
$conn = mysql_connect($hostname,$usuario,$senha); mysql_select_db($banco) or die( "Cant Connect MySQL");
$result = mysql_query("SELECT * FROM users");
$arrayOfChildren = Array();
$i = 0;
while($row = mysql_fetch_array($result))
{
$Balada = array(
'Id'=>($row['Id']),
'Nome'=>($row['Nome']),
'Endereco'=> ($row['Endereco']),
'Telefone'=>($row['Telefone']),
'Description'=>($row['Descricao']),
'Genero' => ($row['Genero']),
'Pagamento' => ($row['FormasPagamento']),
'NomeLista' => ($row['NomeLista'])
);
$arrayOfChildren[] = $Balada;
$i++;
}
$myJSON = json_encode($arrayOfChildren);
echo($myJSON);
?>
The generated JSON: Link
The XML for comparsion: Link