CodeIgniter-MY_Model
CodeIgniter-MY_Model copied to clipboard
Call to a member function num_rows()
I get this error logs in hosted server. The server using PHP 5.5.35
[30-Jan-2017 16:08:48 UTC] PHP Fatal error: Call to a member function num_rows() on a non-object in /home/ardianta/public_html/project1/application/core/MY_Model.php on line 958
But, work fine in my local server (PHP 7.0.13).
The code in line 958 is
if($query->num_rows() > 0)
{
$data = $query->result_array();
$data = $this->trigger('after_get', $data);
$data = $this->_prep_after_read($data,TRUE);
$this->_write_to_cache($data);
return $data;
}
else
{
return FALSE;
}
It can related to PHP version. https://www.codeigniter.com/user_guide/general/requirements.html#server-requirements
PHP version 5.6 or newer is recommended.
It should work on 5.3.7 as well, but we strongly advise you NOT to run such old versions of PHP, because of potential security and performance issues, as well as missing features.
Also try to write query in CI style.