你可以这样尝试:
$this->db->select('*')
$this->db->from('table');
$this->db->like('column', $keyword);
return $this->db->get()->result_array();
如果要控制通配符 (%) 的放置位置,可以使用可选的第三个参数。您的选项是“之前”、“之后”和“两者”(这是默认设置)。
示例:
$this->db->select('*')
$this->db->from('table');
$this->db->like('column', $keyword, 'before');
return $this->db->get()->result_array();
如果您不想使用通配符 (%),您可以将选项“none”传递给可选的第三个参数。
示例:
$this->db->select('*')
$this->db->from('table');
$this->db->like('column', $keyword, 'none');
return $this->db->get()->result_array();
但是,对于您的示例,您必须像 "%keyword sample%" 或 "%keyword%" OR "%simple%" 一样搜索;
例如:
$this->db->like('column', 'keyword simple');
// Produces: WHERE column LIKE '%keyword simple%'
或
$this->db->like('column', 'keyword');
$this->db->or_like('column', 'simple');
// Produces: WHERE column LIKE '%keyword%' OR column LIKE '%simple%'
更多,可以阅读CodeIgniter User Guide