Reputation: 1103
What I want to do is use sum if in codeigniter, it's got error when I run in browser, but I query in MYSQL, there are not error and working nicely.
Here is my code
$this->db->select('sum(if(`monitoring_type` = 1,1,0)) AS independent,sum(if(`monitoring_type` = 2,1,0)) AS buddy,count(*) AS TM, rate_info.qm_title');
$this->db->from('qm.recordings');
$this->db->join('qm.rate_info', 'recordings.record_id = rate_info.record_id');
$query = $this->db->get();
return $query->result();
my Error
MYSQL
Upvotes: 1
Views: 3878
Reputation: 149
Add FALSE
as the second parameter to
$this->db->select('your Query', FALSE);
Update:
It removes the escape identifiers (the backticks) from the select statement which codeigniter does by default for each query. So
SELECT `column1`, `column2` FROM table
will become
SELECT column1, column2 FROM table
Upvotes: 5