CodeIgniter中带有Active Record的"count_all_results"和"where"的问题

Moe*_*ini 5 php database codeigniter

在CodeIngiter用户指南中,他们说了以下代码:

$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status); 
// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
Run Code Online (Sandbox Code Playgroud)

这意味着当我想通过活动记录从数据库中选择一些东西时,我应该使用where方法,它将通过替换AND字段来完成.现在我想创建登录页面,我这样做:

public function True_login($username = '',$password = '')
    {
        $this->db->flush_cache();
        $this->db->where('username',$username);
        $this->db->where('password',$password);
        $count = $this->db->count_all_results('PM_ADMIN_LIST');
        if ($count === 1)
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }
Run Code Online (Sandbox Code Playgroud) 但如果是,它将返回TRUE username=$username OR password = $password.如果在表格中找到一个用户名或密码(并且$count === 1它将返回TRUE)我的prbolem在哪里,我该如何解决?

Bru*_*uce 12

$this->db->count_all_results('PM_ADMIN_LIST');
Run Code Online (Sandbox Code Playgroud)

返回表中的行数并忽略它上面的限制器.

尝试:-

$this->db->where('username',$username);
$this->db->where('password',$password);
$this->db->from('PM_ADMIN_LIST');
$count = $this->db->count_all_results();
Run Code Online (Sandbox Code Playgroud)

另外,进行一些调试 - 如果你知道$count它的价值是什么,那么它可能帮助你弄清楚Active Record查询是错误的,而不是认为它是在做一个OR而不是一个AND.