In the codeigniter framework, we have to use the function $this->db->like(); to generate the LIKE clause. It should be used along with codeigniter select query to automatically generate where and like operators.
$this->db->like('column', 'pattern');<br>
// Generates: WHERE column LIKE '%pattern%'
Take this mysql table 'student' as an example.
id | StudentName | Roll-No | Age | Country |
1 | John Sili | 1058 | 24 | India |
2 | Jhon | 1059 | 22 | Delhi |
3 | Sili | 1060 | 24 | Delhi |
This like query in codeigniter searches the table 'student' for the records having the substring 'sili' in the column 'StudentName'.
$this->db->select('*');
$this->db->from('Books');
$this->db->like('BookName', 'Power');
$query = $this->db->get();
// Produces SQL:
// SELECT * FROM Books WHERE BookName LIKE '%Power%';
id | StudentName | Roll-No | Age | Country |
1 | john Sili | 1058 | 24 | India |
3 | Sili | 1060 | 24 | Delhi |