Welcome Guest, Not a member yet? Register   Sign In
Recover last error on database
#1

Hi All,

please, I am trying recover the error message from a trigger in a database that is returned, but
must be honest, I don't know how I do!.

I have next code:

$result=$this->db->insert('vendedor',$datos);
if ($result==true){
return true;
}
else{
echo "Se produjo un error";
}

But I need the message from database for show it to the client.
I appreciate any help.
Best Regards.
Reply
#2

If you turn db_debug on in database.php config file, it will show the errors/messages.
Reply
#3

You might also try this:

Code:
if ($result==true){
  return true;
}
else{
  echo 'MySQL Error #' . $this->db->_error_number() . ': ' . $this->db->_error_message();
}
However, those are internal functions and shouldn't be relied upon as they can change without notice.
Reply
#4

CI3 has a public error() method that returns both the error number and message.
Reply
#5

Thank you Cronix and Narf !
I'm going to implementing the solution mentioned by Cronix. By the way, I'm working with CI2x
Reply




Theme © iAndrew 2016 - Forum software by © MyBB