Reputation: 841
I just upgraded to 5.5.17 from 5.3.x and the following code stopped working (I get a blank response).
$gestr = mysql_query("SELECT name,age,id FROM users");
$star = array();
while($starid = mysql_fetch_array($gestr)){
$star[] = array('name'=>$starid['name'],'age'=>$starid['age'],'id'=>$starid['id']);
}
$final=array('users'=>$star);
echo json_encode($final);
Please note that I have simplified the SQL statement, but I know it works all the way through the while loop because I can echo out $star[1][name] and it prints a user name.
Upvotes: 0
Views: 110
Reputation: 841
The issue was with json_encode not being able to parse a non-UTF8 encoded name. Thanks to @ChrisForrence for suggesting using json_last_error();
The error was fixed by adding utf8_encode();
$star[] = array('name'=>utf8_encode($starid['name']),'age'=>$starid['age'],'id'=>$starid['id']);
Upvotes: 3