php - CodeIgniter 错误输出 num_rows == 1

标签 php mysql codeigniter

这段代码有什么问题,为什么它返回 num_rows == 0。

function validate() 
    {

        $this->db->where('username', $this->input->post('username'));
        $this->db->where('userpassword', md5($this->input->post('password')));
        $query = $this->db->get('tbluser'); 


        if($query->num_rows == 1)
        {
            return true;
        }


    }

这是我的数据库截图

enter image description here

还有我在 mysql 中执行的查询的屏幕截图

enter image description here

最佳答案

您忘记了()。应该be $query->num_rows()

        if($query->num_rows() == 1)
        {
            return true;
        }

它返回 0 的原因是 $query->num_rows不存在(结果为 false 或 0)。

关于php - CodeIgniter 错误输出 num_rows == 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35884072/

相关文章:

php - 如何从codeigniter项目发送推送通知

python - SQLAlchemy Unicode 难题

php - Codeigniter 将数据库中的数据显示到文本框中

php - 使用 AJAX 在 Codeigniter 中通过选择框过滤表上的数据

php - Codeigniter validation_errors() 总是返回空

php - jQuery,需要 'sortreceive' ajax 调用和 POST 变量的帮助

php - 如何在 Homestead 和我的本地机器之间创建一个共享文件夹

php - 错误的 ELF 类 - PHP 扩展

mysql - 多次更新mysql

php - 如何从 MySQL 获取多行并在 codeigniter 的 View 中单独显示