Reputation: 1270
I want to use following query in Codeigniter:
SELECT `users` . * , `users_profile` . * FROM (`users`) LEFT JOIN `users_profile`
ON `users`.`id` = `users_profile`.`users_id`
WHERE (`loginid` = '$username' OR `email` = '$username' )
AND `password` = '$password' AND `users`.`status` = 'A' LIMIT 1
It is working fine, but when I write this query in Codeigniter format:
$this->db->where('loginid',"$username");
$this->db->or_where('email', "$username");
$this->db->where('password',MD5($password));
$this->db->where('users.status','A');
$this->db->limit(1);
It will return always true what is right syntax?
Upvotes: 2
Views: 4457
Reputation: 4305
May be your query should be like this in codeIgniter.......for reference you can see this link Reference
$this->db->select('*');
$this->db->from('users');
$this->db->join('users_profile', 'users_profile.id = users.id', 'left');
$this->db->where("(loginid = '$username' OR email = '$username') AND password = 'MD5($password) AND status = 'A')'");
Upvotes: 3
Reputation: 1032
You should use the custom string method of where() as this is not possible directly with only ActiveRecord. See this link from the documentation and scroll to the 4th option under the where() function.
Example:
Custom string:
You can write your own clauses manually:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
Upvotes: 1