简体   繁体   中英

How to give two or where condition in mysql query in codeigniter

i need to run a query something similar to this

select * from users where (username='abc' or email='abc@gmail.com') and password='123'

How to do that in codeigniter? I tried something like,

$this->db->select('*');
    $this->db->from('users');
    $this->db->where("email = '" . $email . "'");
    $this->db->or_where("username = '" . $email . "'");
    $this->db->where("password = '" . $password . "'");
    $query = $this->db->get();

Here user may insert value for username as email or username. So need to check username field value both in email field and username field with password

这应该工作

  $this->db->where("(username='abc' or email='abc@gmail.com')");

try this

  $this->db->from('users');
  $this->db->where("(email = '" . $email . "' OR username = '" . $email . "') ");
  $this->db->where("password = '" . $password . "'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM