如何在CodeIgniter中编写查询,如下所示?

时间:2016-01-26 15:18:44

标签: php mysql codeigniter

SELECT * FROM abc WHERE (abc LIKE '%value%' OR def LIKE '%value%') AND ghij NOT IN ('1', '2')

1 个答案:

答案 0 :(得分:3)

您可以转换此查询:

SELECT * FROM abc 
WHERE (abc LIKE '%value%' OR def LIKE '%value%') AND ghij NOT IN ('1', '2')

进入Codeignitor

$this->db->select();
$this->db->from('abc'); // FROM table
$this->db->like('abc', '%value%', 'both');  //WHERE LIKE
$this->db->or_like('def', '%value%');  //WHERE OR LIKE
$this->db->where_not_in('ghij', array('1', '2')); //WHERE NOT IN
$query = $this->db->get(); 
$result = $query->result_array(); // RESULT IN ARRAY

print_r($result);