PHP查询数据库返回空JSON数据

时间:2017-03-23 21:02:37

标签: php json postgresql

我有一个查询我的pgsql表,它应该返回几个响应。事实上,它确实在pgAdmin中。但是,当我通过php运行它并转换为lat时,长时间使用谷歌apis我在响应中得到空括号。有没有人看到我可能做错了什么,它一直工作到昨天,我正在做一些调整代码。我可能无意中做错了什么。

这是php中的查询和后续转换......

$address = pg_query($conn, "
SELECT 
  CONCAT(incident.city, ' ' , incident.state_1)
FROM 
fpscdb001_ws_001.incident
WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
incident.status_1 = 'staging' AND
incident.site_id != '2RS'
;");

if (!$address) {
      echo "Query failed\n";
      exit;
    }
$arr = array();
while ($coordsred = pg_fetch_row($address)){
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$coordsred[0]."&sensor=true";
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->status;
if ($status=="OK") {
    $Lat = (float)$xml->result->geometry->location->lat;
    $Lng = (float)$xml->result->geometry->location->lng;
    $arr[] = array("lat" => $Lat, "lng" => $Lng);
}
}

echo json_encode($arr);

这是调用php的伴侣javascript ...

var xhrred = new XMLHttpRequest();
xhrred.onreadystatechange = function() {

if (xhrred.readyState == 4) {
var arrred = JSON.parse(xhrred.responseText);
console.log(xhrred.responseText);
if(Array.isArray(arrred)){
showMarkersRed(arrred);
}
}
}
xhrred.open('GET', 'markersred.php', true);
xhrred.send();

0 个答案:

没有答案