我有sql查询,我需要转换为codeigniter。 谁能帮我解决这个问题?
SQL 查询是
SELECT * FROM m_slow_log WHERE start_time BETWEEN CAST('2020-01-15%' AS DATE) AND CAST('2020-01-22%' AS DATE);
尝试使用这个
public $table = 'm_slow_log';
function getbetween() {
$where = "start_time BETWEEN CAST('2020-01-15%' AS DATE) AND CAST('2020-01-22%' AS DATE)";
$this->db->where($where);
$this->db->from($this->table);
return $this->db->count_all_results();
}
或者您可以在控制器/视图中设置日期
public $table = 'm_slow_log';
function getbetween($f, $t) {
$this->db->where("start_time BETWEEN '$f' AND '$t'");
$this->db->where($where);
$this->db->from($this->table);
return $this->db->count_all_results();
}
使用简单查询,例如
$this->db->query(SELECT * FROM m_slow_log WHERE start_time BETWEEN CAST('2020-01-15%' AS DATE) AND CAST('2020-01-22%' AS DATE))->row();