Codeigniter中的子字符串查询 [英] substring query in codeigniter
本文介绍了Codeigniter中的子字符串查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要写以下查询。
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`)
最好的方法是什么?
推荐答案
添加第二个参数 FALSE
,例如:
add second parameter FALSE
, like:
$this->db->select('SUBSTRING(zsmonth, 5, 2) as month', FALSE)
->from('tblsales_month');
将第二个参数设置为 FALSE
,CodeIgniter将不要尝试使用反引号保护您的字段或表名。
Setting second parameter to FALSE
, CodeIgniter will not try to protect your field or table names with backticks.
这篇关于Codeigniter中的子字符串查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文