Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter ORM active_记录示例生成器sql,其中id='1'和(c1类'%3%'或c2类'%3%'))_Sql_Codeigniter_Activerecord_Orm_Codeigniter Datamapper - Fatal编程技术网

Codeigniter ORM active_记录示例生成器sql,其中id='1'和(c1类'%3%'或c2类'%3%'))

Codeigniter ORM active_记录示例生成器sql,其中id='1'和(c1类'%3%'或c2类'%3%')),sql,codeigniter,activerecord,orm,codeigniter-datamapper,Sql,Codeigniter,Activerecord,Orm,Codeigniter Datamapper,使用CodeIgniter ORM active_record,我可以生成SQL,例如 示例生成器SQL:。。。就像。。。或者像 encontre不是以组合ORM函数的形式生成类似于我在SQL实例中显示的内容 这是什么,但大多数死亡不是我想要的 $this->db->select('id, c1, c2') ->from('t1') ->where('id', '1111')

使用CodeIgniter ORM active_record,我可以生成SQL,例如

示例生成器SQL:。。。就像。。。或者像

encontre不是以组合ORM函数的形式生成类似于我在SQL实例中显示的内容

这是什么,但大多数死亡不是我想要的

$this->db->select('id, c1, c2')
                ->from('t1')
                ->where('id', '1111')
                ->like('c1',$sSearch)
                ->or_like('c2',$sSearch)
                ->get();

既然你的英语很难理解,我就试试看

我假设您正在尝试在关键字之前或之后将LIKE与通配符%一起使用

可以通过在like或_like中使用before、after和bothdefault来完成此操作

<?php
$this->db
     ->select('id, c1, c2')
     ->from('t1')
     ->where('id', '1111')
      //$this->db->like('title', 'match', 'before'); 
      //Produces: WHERE title LIKE '%match'  
      //$this->db->like('title', 'match', 'after'); 
      //Produces: WHERE title LIKE 'match%' 
      //$this->db->like('title', 'match', 'both'); 
      //Produces: WHERE title LIKE '%match%'
     ->like('c1', $sSearch)
     ->or_like('c2', $sSearch)
     ->get();
也可以使用原始sql执行-


既然你的英语很难理解,我就试试看

我假设您正在尝试在关键字之前或之后将LIKE与通配符%一起使用

可以通过在like或_like中使用before、after和bothdefault来完成此操作

<?php
$this->db
     ->select('id, c1, c2')
     ->from('t1')
     ->where('id', '1111')
      //$this->db->like('title', 'match', 'before'); 
      //Produces: WHERE title LIKE '%match'  
      //$this->db->like('title', 'match', 'after'); 
      //Produces: WHERE title LIKE 'match%' 
      //$this->db->like('title', 'match', 'both'); 
      //Produces: WHERE title LIKE '%match%'
     ->like('c1', $sSearch)
     ->or_like('c2', $sSearch)
     ->get();
也可以使用原始sql执行-

当混合和或时,括号是你的朋友。CodeIgniter的活动记录不支持混合和/或您想要的

CodeIgniter将输出以下查询:

SELECT id, c1, c2 FORM t1 WHERE id ='1' AND c1 LIKE '%3%' OR c2 LIKE '%3%'
SELECT id, c1, c2 FORM t1 WHERE id ='1' AND (c1 LIKE '%3%' OR c2 LIKE '%3%')
显然,这不是你想要的。您可以做的是:将自定义字符串传递到将其用作子句的位置

//因为我们使用的是自定义字符串,所以需要手动转义 $sSearch=$this->db->escape_like_str$sSearch; $this->db->选择'id,c1,c2' ->从't1' ->“id”,“1”在哪里 //这将添加您想要的子句 ->其中'c1'类似于'%$sSearch%'或'c2'类似于'%$sSearch%',NULL,FALSE ->得到; 这将输出所需的查询:

当混合和或时,括号是你的朋友。CodeIgniter的活动记录不支持混合和/或您想要的

CodeIgniter将输出以下查询:

SELECT id, c1, c2 FORM t1 WHERE id ='1' AND c1 LIKE '%3%' OR c2 LIKE '%3%'
SELECT id, c1, c2 FORM t1 WHERE id ='1' AND (c1 LIKE '%3%' OR c2 LIKE '%3%')
显然,这不是你想要的。您可以做的是:将自定义字符串传递到将其用作子句的位置

//因为我们使用的是自定义字符串,所以需要手动转义 $sSearch=$this->db->escape_like_str$sSearch; $this->db->选择'id,c1,c2' ->从't1' ->“id”,“1”在哪里 //这将添加您想要的子句 ->其中'c1'类似于'%$sSearch%'或'c2'类似于'%$sSearch%',NULL,FALSE ->得到; 这将输出所需的查询: