2017-10-28 182 views
1

我是postgresql/postgis的新手,無法解決此問題。我有我使用致命錯誤:帶有消息'SQLSTATE [42601]的未捕獲異常'PDOException':

lonlat.split(","); 

click事件和分裂檢索但當我將它們傳遞到下面的查詢,我收到一個語法錯誤緯度長值。

$sql1=$conn->prepare("select id,ST_Contains(geom,GeomFromText(4326,'POINT(".$lon." ".$lat.")')) as yes_within from public.".$layername);  
$sql1->execute(); 

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at end of input LINE 1: ...om,GeomFromText('POINT()',4326)) as yes_within from public. ^' in C:\xampp\htdocs... Stack trace: #0 PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs... on line 22

回答

0

從錯誤

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at end of input LINE 1: ...om,GeomFromText('POINT()',4326)) as yes_within from public. ^' in C:\xampp\htdocs... Stack trace: #0 PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs... on line 22

這意味着,即使你認爲你從分裂讓他們,你不會從分裂讓他們。您正在連接一個空字符串。這個問題不在PostgreSQL中。

除此之外,不要這樣構造一個點。而是使用,

ST_MakePoint(long,lat)::geography 

它創建了一個geography不是geometry和它毫不文本的解析。

+0

謝謝,我曾經使用過ST_MakePoint。但ST_Contains(geom,MakePoint($ lon,$ lat))作爲yes_within總是返回一個假值。這意味着我正在檢索的緯度永遠不會位於幾何圖形內,也可能是我在基礎圖層上覆蓋(使用geoserver)的圖層,未附加到它下面的圖層,因此我無法從數據庫中檢索任何東西。我是否以錯誤的方式做? – ASood

相關問題