Call to undefined method CI_DB_mysqli_driver::_error_number()
Posted in Codeigniter | 27th July, 2018
Tags.
If you are a codeigniter developer and you are in the middle of a project scratching your heard asking why you cannot get a DB insert/delete success message determined, you are in the right place. You may not be doing anything wrong.
Here is a sample code that can generate the error message:Call to undefined method CI_DB_mysqli_driver::_error_number()
$report=array();
$report['error']=$this->db->_error_number();
$report['message']=$this->db->_error_message();
if(!$report['error'])
{
return true;
}else
{
$this->logmessage('error', 'Attempted to delete user ' . $report['error'] . ' failed (MySQL Error:' . mysql_error() . ')');
return false;
}
The Codeigniter function $this->db->_error_message() has been deprecated and will no longer work in the newer versions of codeigniter.
This error message can be fixed by changing the call
from $this->db->_error_message()
to
$this->db->error();
This method's response will return an array containing code (1 or 0 )and an error message
Your new function should be updated as fillows:
$report=$this->db->error();
if($report['code']==0)
{
//all good
return true;
}else
{
echo $report['message'];
return false;
}
Post a comment