所以我使用預處理語句來處理從我的cordova應用程序到數據庫的JSON調用。PHP PDO調用一個非對象的成員函數execute()
現在,我試圖根據POST
經緯度得到附近的位置,但準備好的聲明不起作用。
當我設置變量只是測試,我得到一個Call to a member function execute() on a non object
錯誤。
我不知道我在做什麼錯了!
error_reporting(E_ALL);
$lat = 42.35674265310388;
$lon = -71.13770473755070;
$miles = 5;
//$lat = $_POST["lat"];
//$lon = $_POST["lon"];
$data = array();
$sth = $mysqli->prepare('SELECT *, (3959 * acos(cos(radians(?)) * cos(radians(lat)) * cos(radians(lon) - radians(?)) + sin(radians(?)) * sin(radians(lat)))) AS distance FROM members WHERE (3959 * acos(cos(radians(?)) * cos(radians(lat)) * cos(radians(lon) - radians(?)) + sin(radians(?)) * sin(radians(lat)))) < ? ORDER BY distance 5');
$sth->execute(array($lat, $lon, $lat, $lat, $lon, $lat, $miles));
$row = $sth->fetch();
$data["markers"][] = array
(
"lat" => $row['lat'],
"lon" => $row['lon']
);
print_r($data);
echo json_encode($data);
另外,我var_dump()
編的$lat
$lon
和$miles
變量,如下所示。
lat - float(42.356742653104)
lon - float(-71.137704737551)
miles - int(5)
你標記這個PDO可是你卻叫你的數據庫變量'$ mysqli'?你的數據庫連接線是什麼樣的? – Novocaine
非常有趣的看到這一個http://stackoverflow.com/questions/18321504/php-select-with-pdo-call-to-a-member-function-prepare-on-a-non-object-error –
@YourCommonSense我改變了一切。另外,novocaine88,我沒有更改變量名稱,但它是通過PDO調用的。 IDK。沒有改變它。 – copilot0910