Welcome Guest, Not a member yet? Register   Sign In
Catch DB error
#8

(This post was last modified: 01-27-2016, 07:55 PM by Shawn.)

(01-22-2016, 08:18 AM)ComputingFroggy Wrote: I've tracked down the problem to the display_error method in system/database/DB_driver class.
At line 1704 (last line of the method), there's :
PHP Code:
exit(8); // EXIT_DATABASE 

So, no wonder each time there's a database error, the application does not go any further: it just stops there !

I commented out this line, and now I do receive an exception and the return of the insert method from my model returns true or false (according to success or failure).

May be that's something that should be considered in the standard CodeIgniter code base.


Cheers,
[email protected]


First off--bad idea to be changing the driver!
Instead, you need to set db_debug to false in your database.php in the config directory:
PHP Code:
'db_debug' => FALSE
This will stop codeigniter from displaying the error automatically

In your model function check for success and explicitly throw an error if the insert returns false.
PHP Code:
public function insert($pRow) {
    if (!
$this->db->insert'P'$pRow)) {
        
$error $this->db->error();
        throw new 
Exception('model_name->record: ' $error['code'] . ' ' $error['message']);
    }
    return 
TRUE

In your controller catch statement you want log the error->message, but not display it to the user, because it can
reveal details of your database that you may not want public.
PHP Code:
} catch  (Exception $e) {
     
log_message('error'$e->getMessage());
     echo 
'Received exception : ' 'friendly detail'"\n";
 } 
Reply


Messages In This Thread
Catch DB error - by ComputingFroggy - 01-21-2016, 06:15 PM
RE: Catch DB error - by Diederik - 01-22-2016, 01:33 AM
RE: Catch DB error - by josepostiga - 01-22-2016, 02:40 AM
RE: Catch DB error - by ComputingFroggy - 01-22-2016, 05:40 AM
RE: Catch DB error - by josepostiga - 01-22-2016, 05:49 AM
RE: Catch DB error - by ComputingFroggy - 01-22-2016, 06:41 AM
RE: Catch DB error - by ComputingFroggy - 01-22-2016, 08:18 AM
RE: Catch DB error - by Shawn - 01-27-2016, 06:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB