Codeigniter LIKE with wildcard(%) Codeigniter LIKE with wildcard(%) codeigniter codeigniter

Codeigniter LIKE with wildcard(%)


$this->db->like() automatically adds the %s and escapes the string. So all you need is

$this->db->like('title', $query);$res = $this->db->get('film');

See the CI documentation for reference: CI 2, CI 3, CI 4


  $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%'


For Full like you can user :

$this->db->like('title',$query);

For %$query you can use

$this->db->like('title', $query, 'before');

and for $query% you can use

$this->db->like('title', $query, 'after');