I have a problem with getting JSON data from mysql phpmyadmin(Version 4.0) table, I have tried PDO and mysql_connect.
My idea: mysql--> PHP--> echo json
The connection to my server works and the SQL statement works perfectly. I have tested it. But the "json_encode"(and some others) of the JSON itself is not possible. The json array is not builted.
Are there settings in PhpMyAdmin which I have to pay attention to?
PDO:
$query = $pdo->prepare('SELECT p.*, count(r.rate) AS rates, avg(r.rate) AS average from plugins p left join rate r on p.title = r.title group by p.title');
$query->execute();
$row = $query->fetchAll();
// send the data encoded as JSON
$json = json_encode($row, JSON_UNESCAPED_UNICODE);
echo $json;
print_r($row);
exit;
Result is:
Array ( [0] => Array ( [id] => 153 [0] => 153 [title] =>
Where am I going wrong? I updated my server to PHP 7.0 and now the code doesn't work. Before the update all is working perfectly and there was a long json array(how it should be)
How it should be
{{"id":"1","title":"ExmapleTitle"....},{"id":"2","title":"ExmapleTitle2"....}...}
$json_arrayand/or$dataempty? Are you sure your query is correct and is being properly executed?