I was learning to use JSON on PHP. I have a DB with a table that holds records of NightClubs, and also a NightClub class.
So far so good, no errors encountered, but when I want to echo the json_encode() It doesn't show me any information.
I've tried to echo son_last_error(); and it returned "0".
I also tried using:
mysql_query('SET CHARACTER SET utf8');
But it did't work.
Here is the code:
<?php
header('Contennt-Type: application/json');
require_once("./inc/Event.inc.php"); //the Boliche object
require_once("./inc/connect.inc.php");//connections to DB
if(mysqli_connect_errno()){
printf("Connect faild: %s\n", mysqli_connect_error());
exit();
}
mysql_query('SET CHARACTER SET utf8');
$query = "SELECT * FROM boliches WHERE id IN (1,2)";
$boliche_array = array();
if($result = $dbc->query($query))
{
while($obj = $result->fetch_object())
{
printf("%s %s %s %s %s %s %s %s </br>", $obj->id, $obj->bname,$obj->place,$obj->OpenTime,$obj->phone,$obj->cost,$obj->age,$obj->website);
$temp_boliche = new Boliche($obj->id, $obj->bname,$obj->place,$obj->OpenTime,$obj->phone,$obj->cost,$obj->age,$obj->website);
$boliche_array[] = $temp_boliche;
}
echo "<br /><br />";
echo '{"students":[';
$dale_data = json_encode($boliche_array[0]);
echo $dale_data;
echo ',<br />';
$dale_data = json_encode($boliche_array[1]);
echo $dale_data . "<br />";
echo ']}';
// Close the database connection
$result->close();
$dbc->close();
}
?>
And this is what I get on my screen
{"students":[{},
{}
]}