Welcome Guest, Not a member yet? Register   Sign In
How can I intercept database requests error?
#1

[eluser]FordEscort[/eluser]
I have just started working with Code Igniter a while and I think it's very interesting.
I'm facing a problem with handling errors.
When running requests that produce database errors (duplicate entry violation for example), the script is exiting and displays the error.
I want to do something like this :
Code:
if ($this->db->update('MyTable', $arrCol))
{
    return true;
}
else
{
    return false;
}

So that the script is not stopped.
Is this possible?;

Thanks.
#2

[eluser]n0xie[/eluser]
If you are using PHP5 you could use a try-catch block:
http://us3.php.net/manual/en/language.exceptions.php which let's your application recover from errors.
#3

[eluser]rogierb[/eluser]
You can turn DB_DEBUG to false and catch the error yourself like n0xie said.
Only I would use mysql_error() assuming you use mysql.
#4

[eluser]FordEscort[/eluser]
It works fine when setting db_debug to false.
Thanks a lot.




Theme © iAndrew 2016 - Forum software by © MyBB