在PHP中无法使用MS Access之间

时间:2018-08-07 05:49:41

标签: php ms-access

我有这段代码应该可以提取特定日期之间的所有数据,但是它不起作用。该查询有效,但它会忽略BETWEEN子句,因此它仍显示所有没有日期的数据。

$statement = Database::prepare("SELECT COUNT(*) AS total_applicants FROM student_applicants a WHERE a.created_at BETWEEN (:start_date AND :end_date) AND a.disabled_at IS NULL AND a.disabled_by IS NULL AND a.deleted_at IS NULL AND a.deleted_by IS NULL");
$statement->bindValue(':start_date', '#5/28/2018 12:00:00 AM#');
$statement->bindValue(':end_date', '#5/28/2018 11:59:59 PM#');
$statement->execute();
$student_applicants = $statement->fetch()['total_applicants'];

1 个答案:

答案 0 :(得分:0)

您要将字符串传递给查询,但是要使用参数,因此您应该传递时间值。

如果您正在使用字符串连接(不应该这样做),那么您的时间格式将是有效的。

尝试以下操作:

$statement = Database::prepare("SELECT COUNT(*) AS total_applicants FROM student_applicants a WHERE a.created_at BETWEEN (:start_date AND :end_date) AND a.disabled_at IS NULL AND a.disabled_by IS NULL AND a.deleted_at IS NULL AND a.deleted_by IS NULL");
$statement->bindValue(':start_date', strtotime('5/28/2018 12:00:00 AM'));
$statement->bindValue(':end_date', strtotime('5/28/2018 11:59:59 PM'));
$statement->execute();
$student_applicants = $statement->fetch()['total_applicants'];