[英]Convert sql query in query in Active Record in codeigniter
I need to convert this query in an active Record query. 我需要在活动的记录查询中转换此查询。
SELECT * FROM test WHERE CAST(date AS DATE) = '2017-06-19' AND `ip` = '::1'
this is what I tried but the where
with the date
does not work 这是我尝试过的方法,但是date
where
不起作用
function search($date, $ip){
$this->db->select('cast(date as Date)');
$this->db->where('date', $date);
$this->db->where('ip', $ip);
return $this->db->get('visitas');
}
this produce something like this 这会产生这样的事情
SELECT cast(fecha as Date) FROM (`visitas`) WHERE `ip` = '::1'
thank´s in advance. 提前致谢。
I'm not able to test this at the moment but I believe it's what you're looking for. 我目前无法对此进行测试,但我相信这就是您想要的。
// Convert your date string to mysql datetime
$date = date( "Y-m-d" , strtotime("2017-06-19") );
// Build the query
$this->db->select('*')->from('visitas')
->where('CAST(date AS DATE)=', $date)
->where('ip', '::1');
$query = $this->db->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.