记录少于 15 分钟的活动记录
Active record where record is less than 15 minutes old
我正在使用 Codeingiter 的活动记录,需要检查 15 分钟以内的条目。
我已经尝试了以下方法,我认为它会起作用。
$this->EE->db->select('entry_id')
->from('exp_channel_titles')
->where('status', $status)
->where('channel_id', $channel)
->where(FROM_UNIXTIME('entry_date') >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE))
->order_by('entry_date', 'desc');
有谁知道是否可以这样做?
我曾希望这会在 where 子句中起作用
FROM_UNIXTIME('entry_date') >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)
来自https://ellislab.com/codeigniter/user-guide/database/active_record.html:
$this->db->where() accepts an optional third parameter. If you set it
to FALSE, CodeIgniter will not try to protect your field or table
names with backticks.
$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
因此您应该能够传递如下字符串:
->where('FROM_UNIXTIME(`entry_date`) >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)', NULL, FALSE)
我正在使用 Codeingiter 的活动记录,需要检查 15 分钟以内的条目。
我已经尝试了以下方法,我认为它会起作用。
$this->EE->db->select('entry_id')
->from('exp_channel_titles')
->where('status', $status)
->where('channel_id', $channel)
->where(FROM_UNIXTIME('entry_date') >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE))
->order_by('entry_date', 'desc');
有谁知道是否可以这样做?
我曾希望这会在 where 子句中起作用
FROM_UNIXTIME('entry_date') >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)
来自https://ellislab.com/codeigniter/user-guide/database/active_record.html:
$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
因此您应该能够传递如下字符串:
->where('FROM_UNIXTIME(`entry_date`) >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)', NULL, FALSE)