问题
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