使用CodeIgniter调用成员函数result() [英] Call to a member function result() using CodeIgniter

查看:113
本文介绍了使用CodeIgniter调用成员函数result()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用mysql和codeigniter时遇到了一个奇怪的问题.我收到以下错误消息:

I am having a strange issue with mysql and codeigniter. I am getting the following error message:

Fatal error: Call to a member function result() on a non-object in

控制器:

class Event extends Client_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Event_Model', '', TRUE);
    }

    function pending()
    {
        $data['query'] = $this->Event_Model->get_events_list("pending");
        $this->load->view('event/pending', $data);
    }   

}

型号:

class Event_Model extends Client_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function get_events_list($event_status = '')
    {
        $query = $this->db->query("SELECT * FROM tbl_events WHERE event_status= ? ORDER BY event_id DESC", array($event_status));

        return $query->result();// Error is on this line
    }
}

自动加载:

$autoload['libraries'] = array('database', 'session');

感谢您的帮助.我有些疑问,我的MySQL可能会超时?

Any help is appreciated. I have some doubts that my mysql might time-out?

推荐答案

该错误很可能是由于查询(以及生成的result()对象)为空的事实所致.在尝试使用result()对象之前,请确保查询实际上返回了至少一条记录:

The error is likely due to the fact that the query (and resulting result() object) are empty. Ensure that the query actually returns at least one record before attempting to use the result() object:

if($query->num_rows() > 0){
    return $query->result();
}

这篇关于使用CodeIgniter调用成员函数result()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆