2011-04-11 24 views
1

我有以下查詢,我需要在PHP中執行。問題是我需要執行主查詢之前的設置查詢。該組查詢是形式的MySQL查詢在PHP

SET @center = GeomFromText('POINT(33.3666667 35.1666667)'); 
SET @radius = 1; 
SET @bbox = CONCAT('POLYGON((', 
X(@center) - @radius, ' ', Y(@center) - @radius, ',', 
X(@center) + @radius, ' ', Y(@center) - @radius, ',', 
X(@center) + @radius, ' ', Y(@center) + @radius, ',', 
X(@center) - @radius, ' ', Y(@center) + @radius, ',', 
X(@center) - @radius, ' ', Y(@center) - @radius, '))' 
); 

和主查詢

SELECT 
users_profile.id, 
GLength(LineString(users_profile.location,GeomFromText('POINT(33.3666667 35.1666667)'))) * 100 as distance 

FROM 
users_profile 

WHERE 
Intersects(users_profile.location, GeomFromText(@bbox)) 
AND (GLength(LineString(users_profile.location,GeomFromText('POINT(33.3666667 35.1666667)'))) * 100) < 10 

ORDER BY distance 

我如何在PHP執行此?我不能這樣做,因爲4種不同的查詢,我也不能做到這一點1

回答

0

我不認爲你可以執行這樣的第一個查詢。嘗試將它作爲一個存儲過程編寫,然後從PHP調用它。

+0

我以爲多想 – mbouclas 2011-04-11 14:56:20

0

我發現了一些可能有所幫助的東西here。我沒有使用或測試它,所以YMMV。

+0

畢竟我是走mysqli的路。由於mysqli執行多個查詢的方式,這遠非理想。理想的做法是將4個查詢改爲1,但我所有的測試都失敗了。 – mbouclas 2011-04-12 06:55:22