我正在尝试将数据从PhpMyAdmin导出为JSON格式
此代码适用于select lat,lng from googlemaps
,但不适用于address
列
我的代码是:
<?php
$con=mysqli_connect("localhost","root","","googlemaps");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT lat,lng,`addr` FROM infos";
if ($result = mysqli_query($con, $sql))
{
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row =mysqli_fetch_array($result))
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
$fp = fopen('results01.json', 'w');
fwrite($fp, "{ \"tab\": ");
fwrite($fp, json_encode($resultArray));
fwrite($fp, " }");
fclose($fp);
echo json_encode($resultArray);
//var_dump($resultArray);
?>
infos
表的屏幕截图:
答案 0 :(得分:1)
刚刚找到解决方案,它实际上是在选择查询之前添加它:
mysqli_set_charset($con, "utf8");
$sql = "SELECT lat,lng,`addr` FROM infos";
if ($result = mysqli_query($con, $sql))
{......}