Call to member function result() of non object codeigniter

半世苍凉 提交于 2019-12-25 17:02:11

问题


public function get_priority($priority_id = "") {
    if ($priority_id == "") {
        $qry = $this->db->get("tm_priority");
    } else {
        $qry = $this->db->query("SELECT * FROM tm_priority WHERE nt_id = {$priority_id}");
        echo $this->db->last_query();
    }
    print_r($qry->result());
}

In my above model function I echo the last_query() for debugging purpose and it's giving me the following result

 SELECT * FROM tm_priority WHERE nt_id = 1

When I run this query directly into my mysqlyog, it's working fine.

Then what else could be the reason of the error below

Fatal error: Call to a member function result() on a non-object in /home/staging/erp/application/models/tasks/task_model.php on line 341

回答1:


You should try to check for number of returned rows before outputting it :

if($qry->num_rows() > 0){
    print_r($qry->result());
}


来源:https://stackoverflow.com/questions/22685990/call-to-member-function-result-of-non-object-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!