Welcome Guest, Not a member yet? Register   Sign In
i need help in mysql like query
#1

how to write the direct mysql statement in CI model
for ex:-
   
      SELECT
    employeeNumber, lastName, firstName
FROM
    employees
WHERE
    (lastName LIKE '%B%' or firstName LIkE '%d%') and employeeNumber LIKE '%112%' and (Country LIKE '%US%' or Country LIkE '%UK%');

this statement is mysql formate

how to write the same logic in the CI model,
kindly i request to help me.
thanking you
Reply
#2

Please, have a look at the Database Reference in the CI documentation:
https://www.codeigniter.com/userguide3/d...eries.html

For me, the Query Builder works great.
Your query would be like this in Query Builder:

PHP Code:
public function get_employees()
{
 
 $this->db
  
->select('employeeNumber, lastName, firstName')
 
 ->from('employees')
 
 ->group_start()
 
 ->like('lastName','B','both')
 
 ->or_like('firstName','d','both')
 
 ->group_end()
 
 ->like('employeeNumber','112','both')
 
 ->group_start()
 
 ->like('Country','US','both')
 
 ->or_like('Country','UK','both')
 
 ->group_end();
 
 $query $this->db->get();
 
 if ($query->num_rows() > 0) {
 
   return $query->result();
 
 }
 
 else {
 
   return FALSE;
 
 }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB