[英]Question Marks in PHP Prepared Statement not working?
我正在嘗試從給定緯度和經度100米范圍內從數據庫中獲取一些位置。
我在Google網站上找到了一個查詢,您可以執行此操作,但是,當我刪除查詢中的變量並將它們替換為問號(如您在“准備好的語句”中應有的那樣)時,它將不起作用。
我的查詢如下:
$getLocation = $db->prepare("
SELECT
id, title, lat, `long`, verified, (
3959 * acos (
cos ( radians(?) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians(?) )
+ sin ( radians(?) )
* sin( radians( lat ) )
)
) AS distance
FROM markers
HAVING distance < 0.0621371192
ORDER BY distance
LIMIT 1;
");
$getLocation->bind_param("sss", $newLatitude, $newLongitude, $newLatitude);
$getLocation->execute();
$getLocation->store_result();
$getLocation->bind_result($locId, $locTitle, $locLat, $locLong, $locVerified, $locDist);
if($getLocation->num_rows > 0) {
while($getLocation->fetch()) {
echo "yes";
}
}
else {
echo "no :(";
}
我不是Prepared Statements專家,所以請告訴我我做錯了什么。
謝謝,
好吧,最終我通過將查詢更改為此來解決了我的問題:
$getLocation = $db->prepare("
SELECT
id, title, lat, `long`, verified, (
3959 * acos (
cos ( radians(?) )
* cos( radians( lat ) )
* cos( radians( `long` ) - radians(?) )
+ sin ( radians(?) )
* sin( radians( lat ) )
)
) AS distance
FROM marker
HAVING distance < 0.0621371192
ORDER BY distance
LIMIT 1;
");
現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.