Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substring query in codeigniter

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?

like image 601
Dinuka Thilanga Avatar asked Dec 11 '25 09:12

Dinuka Thilanga


1 Answers

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.

like image 154
Sudhir Bastakoti Avatar answered Dec 13 '25 21:12

Sudhir Bastakoti