-1
在phpMyAdmin工作臺中運行查詢時,結果與預期的一樣,total
有一個值。但是,在PHP中運行相同的代碼時,PDO total
始終是0.這裏是SQLFiddle。PHP PDO獲取與工作臺不同的MySQL結果
PHP代碼:
$stmt = "
SELECT COUNT(*) as `total`
FROM `provider_availability`
WHERE `provider_availability`.`practitioner_id` = :practitioner_id
AND `provider_availability`.`weekday` = :weekday
AND `provider_availability`.`ID` != :edit_id
AND `deleted` = 0
AND (:start_time BETWEEN `provider_availability`.`starting_time` AND `provider_availability`.`ending_time`
OR :end_time BETWEEN `provider_availability`.`starting_time` AND `provider_availability`.`ending_time`)";
$query = $this->connection->prepare($stmt);
$query->bindValue(':practitioner_id', $_SESSION['user']['ID'], PDO::PARAM_INT);
$query->bindValue(':weekday', $weekday, PDO::PARAM_INT);
$query->bindValue(':edit_id', $edit_id, PDO::PARAM_INT);
$query->bindValue(':start_time', $start_time, PDO::PARAM_STR);
$query->bindValue(':end_time', $end_time, PDO::PARAM_STR);
if ($query->execute() == true) {
$row = $query->fetch(PDO::FETCH_ASSOC);
return $row['total'];
} else {
die(json_encode([
"success" => false,
"reason" => $query->errorInfo()
]));
}
你注意到了什麼嗎?我不是在指責PDO,我喜歡PDO,這讓我的生活變得更加輕鬆。 – kneeki
另外,我想知道你是否真的只對重疊感興趣 - 所以,my_start開始 –
Strawberry