I have two functions below that query the PHP and then print the json out.
I tried on my local machine AMPP Apache server, everything works with the Json printed. When I tried on my host machine (with all DB setup, tested good), somehow the print json_encode($rows)
doesn't print anything on the remote host server.
So I added the debug echo sizeof($rows)
below, and indeed there are 8 records as per expected. What can't the print json_encode($rows)
print anything? How to further debug?
function queryPrintJson($cnx, $query) {
$rows=queryReturnJsonArray($cnx, $query);
echo sizeof($rows);
print json_encode($rows);
}
function queryReturnJsonArray($cnx, $query) {
$result=mysqli_query($cnx, $query) or die ("Can't execute query!");
$rows = array();
while($obj = $result->fetch_object()){
$rows[] = $obj;
}
$result->close();
return $rows;
}
p/s: the same function works on the same remote host-server, for another db. It also works on my localhost.
*UPDATED
'var_dump(json_encode($rows), json_last_error())' shows bool(false) int(5)
. Don't know what it means.
My query is simply $newsquery = "SELECT * FROM newstbl where Status = 1";
*UPDATE
After further debugging, I found that one of the field which is a description
field that has long data... That field if omitted, everything works. But if included, it doesn't print out.
This also could imply not related to UTF-8 as well. As the description
is all in normal english character. Hence doesn't seems like a duplicate of the other question.
p/s: Not sure who gave the down-vote to all the answers below, as it does help my debugging. Whoever does that need to be responsible before giving a down vote to the below answer. They all does help my debugging.