I'm working on a personal project with an open database, and I need a JSON file from a MYSQL query, I've been trying to solve this problem for a few days now and I'm having a hard time getting the name of the My data. Example: I make a query to list all states, I can get the json with the ID, UF, Region, when I put the field name, it returns nothing to me and gives the error Resource interpreted as Document but transferred with MIME type application / json: " link ". My goal is to get all the data from the query and return a JSON to deal with GeoCharts.
<?php
$con = mysqli_connect("localhost","root","3919223","DatasusNew") or die("Error " . mysqli_error($con));
mysqli_query('SET NAMES utf8;');
$var = array();
$sql = "SELECT * FROM estados";
$result = mysqli_query($con, $sql);
foreach ($result as $row) {
$return[] = [
'nome' => $row['nome'],
'idEstado' => $row['idEstado'],
'uf' => $row['uf'],
'regiao' => $row['regiao']
];
}
$dbh = null;
header('Content-type: application/json');
echo json_encode($return);
?>
Has anyone ever had this problem? Or any tips?