用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1310|回复: 4
收起左侧

[HELP] call to a member function num_rows() on a non-object

[复制链接]
发表于 2015-1-16 15:09:48 | 显示全部楼层 |阅读模式
database是在autoload中自动加载的,却报了错误:
call to a member function num_rows() on a non-object

代码:
$Mobile = $this->input->post('Mobile', TRUE);
$query = $this->db->get_where('myTable', array('Mobile' => $Mobile), 1);
if(0 < $query->num_rows()) {
    $resultData = array (
        'result' => '号码已经存在'
    );
    echo json_encode($resultData);
}

我在CI的用户指南中看到就是这么写的啊?

发表于 2015-1-16 15:31:42 | 显示全部楼层
貼上你這段程式碼所在的"檔案所有內容"及"所在資料夾路徑"
发表于 2015-1-16 16:53:11 | 显示全部楼层
可能是你的“$this->db->get_where('myTable', array('Mobile' => $Mobile), 1);”这个语句返回的结果为空。
发表于 2015-1-16 17:59:05 | 显示全部楼层
SQL语句错了 看看是表不存在 还是字段不存在
 楼主| 发表于 2015-1-16 20:21:01 | 显示全部楼层
谢谢大家的回复,我再查查数据库。

本版积分规则