substring query in codeigniter

codeigniter, php, sql

Solution

add second parameter `FALSE`, like:

$this->db->select('SUBSTRING(zsmonth, 5, 2) as month', FALSE)
        ->from('tblsales_month'); 

Setting second parameter to `FALSE`, CodeIgniter will not try to protect your field or table names with backticks.

Problem

I want a write following query. ``` SELECT SUBSTRING(zsmonth, 5, 2) as month FROM (`tblsales_month`) ``` So i wrote following code. ``` $this->db->select('SUBSTRING(zsmonth, 5, 2) as month') ->from('tblsales_month'); ``` But it generate following query with unnecessary back quote. ``` SELECT SUBSTRING(zsmonth, `5`, `2)` as month FROM (`tblsales_month`) ``` What is the best way to do that?

Original source