$app->get('/view/appointment/:databaseID/:userID/:appointmentID', function($databaseID, $userID, $appointmentID) use($app) {
$params['databaseID'] = $databaseID; //$request->getAttribute('databaseID');
$id = $userID; //$request->getAttribute('userID');
$date = $appointmentID; //$request->getAttribute('appointmentID');
$sql = "SELECT imapt_date, imapt_start_time, imapt_end_time, imapt_patient_id, imapt_procedure
from im_ap_timetable inner join im_practioner on
im_ap_timetable.impract_id=im_practioner.impract_id inner join
im_users_cd on im_practioner.user_id=im_users_cd.user_id
where im_users_cd.user_id = :id and im_ap_timetable.imapt_date = :date";
try {
$db = getDB($params['databaseID']);
$stmt = $db->prepare($sql);
$query = compact('id');
$stmt->execute($query);
$patient = $stmt->fetchAll(PDO::FETCH_ASSOC);
$status = array('success' => '200');
echo json_encode(compact('patient','status'));
} catch (Exception $e) {
$status = array('error' => $e->getMessage());
echo json_encode(compact('status'));
}
});
答案 0 :(得分:1)
您有两个占位符::id
和:date
。
但你只绑定了一个 - :id
。
您也需要绑定:date
。在你的情况下它是:
$query = compact('id', 'date');
答案 1 :(得分:0)
您可以使用bindParam
方法将参数绑定到SQL查询。
http://php.net/manual/en/pdostatement.bindparam.php
您也可以将它们传递到execute
方法中的数组中。
$stmt->execute($query, [':id' => $id, ':date' => $date]);