使用PHP的PDO我想获得在具有当前一周内的起始日期我的数据库表中的所有行。 为了计算这个星期我用下面的第一个和最后一个日期:
$week_start = date('d-m-Y',time()+( 1 - date('w'))*24*3600);
$week_end = date('d-m-Y',time()+( 7 - date('w'))*24*3600);
然后我的PDO查询中我有:
$query = "
SELECT
*
FROM
bookings as bb
INNER JOIN
reservation as br ON bb.booking_id=br.bookings_id
INNER JOIN
cars as bc ON br.car_id=bc.car_id
WHERE
payment_success=1 AND
is_block=false AND
is_deleted=0 AND
DATE_FORMAT(start_date, '%d-%m-%Y')
BETWEEN '".$week_start."' AND '".$week_end."'
";
try {
$stmt = DB::get()->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
}
catch(PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
}
foreach($rows as $row):
$row['booking_id'] etc...
endforeach;
问题是我没有得到任何行输出显示出来,尽管具有这周之内的开始日期的多个预订