Active record where record is less than 15 minutes old

点点圈 提交于 2019-12-11 12:51:38

问题


I am using Codeingiter's active record and need to check for entries that are less than 15 minutes old.

I have tried the following, which I thought would work.

$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'); 

Does anyone know if its possible to do this?

I had hoped this would do work in a where clause"

FROM_UNIXTIME('entry_date') >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)

回答1:


From 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);

So you should be able to pass a string like:

 ->where('FROM_UNIXTIME(`entry_date`) >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)', NULL, FALSE)


来源:https://stackoverflow.com/questions/31322314/active-record-where-record-is-less-than-15-minutes-old

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!