我有以下原始查询:
$results = Db::select( Db::raw("SELECT HOUR(created_at) as hour, COUNT(*) as count
FROM `visited`
WHERE created_at >= DATE_SUB(NOW(),INTERVAL 16 DAY)
GROUP BY HOUR(created_at)") );
我需要参数化天间隔,所以我尝试了这个:
$days = 16;
$results = Db::select( Db::raw("SELECT HOUR(created_at) as hour, COUNT(*) as count
FROM `visited`
WHERE created_at >= DATE_SUB(NOW(),INTERVAL :days DAY)
GROUP BY HOUR(created_at)", ["days" => $days]) );
但我收到以下错误:
“SQLSTATE [HY000]:一般错误:2031
显然绑定不起作用。我究竟做错了什么?