Welcome Guest, Not a member yet? Register   Sign In
Database Error Codes
#1

[eluser]blcArmadillo[/eluser]
How should I go about getting the error code if a query fails. Right now CI just uses the DB error page to output the error code and such. Is there a way I can get the code so that my program can respond appropriately? I know there are functions such as mysql_errno and mysqli->errno. Should I just use these or is there some built in CI function that would better suited for my needs? Thanks for the help.
#2

[eluser]crnalajna[/eluser]
You may extend DB_mysql_driver and do what you want with that data.
Example, you may send email with that error but not show it to user.


/application/libraries/MY_DB_mysql_driver.php
Code:
class MY_DB_mysql_driver extends CI_DB_mysql_driver {

    function __construct($params){
        parent::__construct($params);
        log_message('debug', 'Extended DB driver class instantiated!');
    }

    function display_error($error = '', $swap = '', $native = FALSE)
    {
        
        // do what you want here
        print_r( $error );

        exit;

        /* -----------------------------
        /*  original content
        
        $LANG =& load_class('Language');
        $LANG->load('db');

        $heading = $LANG->line('db_error_heading');

        if ($native == TRUE)
        {
            $message = $error;
        }
        else
        {
            $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
        }

        $error =& load_class('Exceptions');
        echo $error->show_error($heading, $message, 'error_db');
        exit;
        
        ------------------------ */
    }

}

To be able to extend CI_DB class you need to extend Loader class first.
http://codeigniter.com/wiki/Extending_Database_Drivers/




Theme © iAndrew 2016 - Forum software by © MyBB