我試圖從PHP使用Postgress表中獲取數據。我向查詢提供參數,儘管我知道表中應該有數據返回,但返回的數組是空的。PHP和Postgres查詢問題
<?php
ini_set('memory_limit', '1024M');
// Connecting, selecting database
$dbconn = pg_connect(***My connection details***)
or die('Could not connect: ' . pg_last_error());
$lat1 = 50.5;
$lat2 = 58.0;
$lng1 = -3.5;
$lng2 = -7.0;
$colour_points = 'SELECT lat,lng,price,address_string FROM house_price_data_db.main where lat>=$1 and lat<=$2 and lng>=$3 and lng<=$4';
$result_pinpoints_points = pg_query_params($dbconn,$colour_points,array($lat1,$lat2,$lng1,$lng2)) or die('Query failed: ' . pg_last_error());
$pin_points_array = array();
while($r = pg_fetch_assoc($result_pinpoints_points)) {
$pin_points_array[] = $r;
}
header("Content-type: application/json"); // set the header to json
echo(json_encode(array_values($pin_points_array), JSON_NUMERIC_CHECK)); // this will return json
pg_close($dbconn);
?>
有關如何解決/解決這個問題的任何建議?
您是否嘗試過測試與查詢參數直接在數據庫上? – 2015-02-09 13:15:23
你可以爲'$ 1','$ 2','$ 3','$ 4'指定一些值嗎? – 2015-02-09 13:26:05
根據定義的'$ result_pintpoints_points'行,值被指定爲$ lat1,$ lat2,$ lng1,$ lng2。我找出了我出錯的地方,並在下面解釋。 – JellyTots 2015-02-09 13:28:16