在phpMyAdmin工作台中运行查询时,结果与预期一致,total
具有值。但是,在PHP中运行相同的代码时,PDO total
始终为0.这是SQLFiddle。
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()
]));
}
答案 0 :(得分:0)
这是不可能的。
PDO将从不为您提供不同的结果,因为发送的查询和连接的数据库是相同的。