如何防止codeigniter在正则表达式中插入空格

时间:2015-11-25 21:26:56

标签: regex codeigniter

如何防止codeigniter在正则表达式中插入空格。因为当它发生时,它会破坏查询。

例如,我有一个使用正则表达式间隔的查询,但是当codeigniter创建sql时,它会在正则表达式间隔中插入一个空格来破坏查询。 基本上,codeigniter在正则表达式中插入一个空格来打破我的查询

我的codeigniter代码

$query = $this->db->select("@a:=@a+1 sno, t.trainingID, trgDescName, totalParticipants, (SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{12}[13579]$' and `trainingID` = t.trainingID) as `males`, (SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{12}[24680]$' and `trainingID` = t.trainingID) as `females`, (SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{0,12}$' and `trainingID` = t.trainingID) as `invalid cnic`, districtName, projectName, concat_ws(' ', fromDate, toDate) as dates , venue ", FALSE)
->join('trg_desc as td', 't.trgDescID = td.trgDescID', 'left')
->join('project as pj', 't.projectID = pj.projectID', 'left')
->join('training_district as tdi', 't.trainingID = tdi.trainingID', 'left')
->limit(20, 0)
->get('training as t');

为哪个codeigniter创建以下引发错误的代码 得到错误'无效的重复次数'来自regexp

select  @a:=@a+1 sno, t.trainingID, trgDescName, totalParticipants, 
(SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{12}[13579]$' and `trainingID` = t.trainingID) as `males`,
(SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{12}[24680]$' and `trainingID` = t.trainingID) as `females`, 
(SELECT count(cnic) FROM participant WHERE cnic regexp '^[0-9]{0, 12}$' and `trainingID` = t.trainingID) as `invalid cnic`, 
districtName, projectName, concat_ws(" ", fromDate, toDate) as dates , venue
from training as t
left join trg_desc as td on t.trgDescID = td.trgDescID
left join project as pj on t.projectID = pj.projectID
left join training_district as tdi on t.trainingID = tdi.trainingID
limit 0, 20;

有没有办法防止codeigniter插入空格?

1 个答案:

答案 0 :(得分:0)

有一种方法 - 不要使用查询构建器。

对于像你所展示的那样的查询,你几乎没有使用它。您实际上是在自己编写所有SQL ,在另一个RDBMS上,查询无法以相同的方式工作,这是使用查询构建器的全部要点 - 可移植性。