$sql="select count(*) from table where a=a and b=d and(c like %a% and d like %a%)"; 这样的SQL语句用CI的Active Record 类 来写该怎么写 中间的 and(c like %a% and d like %a%)";
$this->db->escape() 这个函数将会确定数据类型,以便仅对字符串类型数据进行转义。并且,它也会自动把数据用单引号括起来,所以你不必手动添加单引号,用法如下:
$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";
$this->db->escape_str() 此函数将忽略数据类型对传入数据进行转义。更多时候你将使用上面的函数而不是这个。这个函数的使用方法是:
$sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')";
$this->db->escape_like_str() This method should be used when strings are to be used in LIKE conditions so that LIKE wildcards ('%', '_') in the string are also properly escaped.
$search = '20% raise';
$sql = "SELECT id FROM table WHERE column LIKE '%".$this->db->escape_like_str($search)."%'";