简体   繁体   English

Mysql查询使用codeigniter检查用户名和密码

[英]Mysql query to check username and password using codeigniter

I have a table to store the user details and it include fields such as email,mobile and password.我有一个表来存储用户详细信息,它包括电子邮件、手机和密码等字段。 Here my username to login can be either email or mobile number and I need to compare it with password.这里我登录的用户名可以是电子邮件或手机号码,我需要将其与密码进行比较。 How can I write the query for it?我该如何编写查询? I have written it like this, but it's not working我是这样写的,但它不起作用

$this->db->select('*');
        $this->db->from('user');
        $this->db->where('email',$data['email']);
        $this->db->or_where('mobile',$data['email']);

        $this->db->where('password',$data['password']);

        $this->db->get()->row();

I need code to compare username as either email or mobile with its password.我需要代码来将用户名作为电子邮件或移动设备与其密码进行比较。

As is specified on official CodeIgniter documentation ( https://www.codeigniter.com/user_guide/database/query_builder.html#query-grouping ), you can group "where" statements.正如官方 CodeIgniter 文档 ( https://www.codeigniter.com/user_guide/database/query_builder.html#query-grouping ) 中指定的那样,您可以对“where”语句进行分组。 So, for achieving what you need, you should do the following:因此,为了实现您的需求,您应该执行以下操作:

$this->db->select('*')
    ->from('user')
    ->group_start()
        ->where('email',$data['email'])
        ->or_where('mobile',$data['email'])
    ->group_end()
    ->where('password',$data['password'])
    ->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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