我试图将我的MYSQL表数据转换成JSON。我正在尝试使用json_encode()。但是它没有起作用。它没有返回任何内容。我已经检查了控制台,也没有抛出任何错误。我错过了什么?
<?php
//open connection to mysql db
$connection = mysqli_connect("localhost","root","","maps") or die("Error " . mysqli_error($connection));
//fetch table rows from mysql db
$sql = "select * from locations";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
//create an array
$emparray[] = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);
//close the db connection
mysqli_close($connection);
?>