【问题标题】:I need to fix with code igniter query我需要修复代码点火器查询
【发布时间】:2016-04-13 18:38:42
【问题描述】:

我正在尝试根据 table3 id 数组从 table1 和 table2 获取详细信息。 table3 id 和 table1 id 在 table2 中可用。

// $ids 是一个 id 数组,例如:Array ( [ids] => 10,11 )

function get_detail($ids) { 

    $this->db->select('*');
    $this->db->from('table1');
    $this->db->join('table2', 'table1.aID = table2.aID');
    $this->db->join('table3', 'table2.bID = table3.bID','left');
    $this->db->where('table3.bID', $ids); 
    $query = $this->db->get();      

}

【问题讨论】:

    标签: sql codeigniter codeigniter-2 code-injection


    【解决方案1】:

    当您有多个值时,您应该使用 IN

    替换

    $this->db->where();
    

    $this->db->where_in();
    

    两者都取 (col, value);

    注意:// $ids = Array (10,11);

    【讨论】:

      【解决方案2】:

      你好你使用 where_in 像这样

      function get_detail($ids) { 
      
          $this->db->select('*');
          $this->db->from('table1');
          $this->db->join('table2', 'table1.aID = table2.aID');
          $this->db->join('table3', 'table2.bID = table3.bID','left');
          $this->db->where_in('table3.bID', $ids); 
          $query = $this->db->get();      
      
      }
      

      注意:以数组格式传递$ids

      $ids = 数组 (10,11);

      【讨论】:

      • 如何将 foreach() 用于像 Array ( [sectionIDs] => 1,2,3,4 ) 之类的数组,或者如何破坏 Array ( [sectionIDs] => 1,2,3 ,4 ) 转入Array ( [0] => 1,[1] => 2,[2] => 3,[3] => 4 )
      【解决方案3】:

      你可以使用数组

      $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
      
      $this->db->where($array);
      

      【讨论】:

      • 如何将 foreach() 用于像 Array ( [sectionIDs] => 1,2,3,4 ) 之类的数组,或者如何破坏 Array ( [sectionIDs] => 1,2,3 ,4 ) 转入Array ( [0] =&gt; 1,[1] =&gt; 2,[2] =&gt; 3,[3] =&gt; 4 )
      猜你喜欢
      • 2023-03-31
      • 2014-02-14
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多