Welcome Guest, Not a member yet? Register   Sign In
DB Errors log
#1

[eluser]gon[/eluser]
Hi,

How do you guys keep a log of possible failed queries?
When setting db_debug to true, they get logged, but an error screen is also shown.
Also, tables get locked when using transactions.


So what I do is modify the display_error function, on DB_driver.php:

Code:
function display_error($error = '', $swap = '', $native = FALSE)
    {
        return false;


//        $LANG = new CI_Lang();
        $LANG = new CI_Language();
        $LANG->load('db');

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

        if ( ! class_exists('CI_Exceptions'))
        {
//            include(BASEPATH.'core/Exceptions'.EXT);
            include(BASEPATH.'libraries/Exceptions'.EXT);
        }
        
        $error = new CI_Exceptions();
        echo $error->show_error('An Error Was Encountered', $message, 'error_db');
        exit;
    }

Is there another way to do this without touching inside CI?

I would suggest to add a different database config param for logging and displaying errors.

Regards.
#2

[eluser]marmida[/eluser]
Long story short: I don't see an easy way to add something like logging without going outside application/.

Long story long: I myself just looked into the CI internals to figure out more about how to build a separate log for all queries and make it configurable. It's not all that easy, since by the time the query is fully expanded with all driver-specific bindings in it, you're all the way down into the driver class's _execute method. Because of the active record / regular and driver distinctions, there's a special bit of macro-esque magic used to dynamically define an adapter class in DB.php; because of these special considerations, the basic load_class() function isn't used, and because of that, it doesn't look inside application/ for anything to do with database drivers for subclassing.

You mentioned database locking when transactions are enabled; I'm encountering weird problems with innodb that sound like they may be related. I can't find anything that suggests actual locks being run into mysql. Did you find anything that explicitly mentions database-side locking?
#3

[eluser]gon[/eluser]
Quote:Long story long: I myself just looked into the CI internals to figure out more about how to build a separate log for all queries and make it configurable. It’s not all that easy, since by the time the query is fully expanded with all driver-specific bindings in it, you’re all the way down into the driver class’s _execute method. Because of the active record / regular and driver distinctions, there’s a special bit of macro-esque magic used to dynamically define an adapter class in DB.php; because of these special considerations, the basic load_class() function isn’t used, and because of that, it doesn’t look inside application/ for anything to do with database drivers for subclassing.

To avoid getting inside specific DB drivers, I'm modifying only DB_driver.php.

Quote:You mentioned database locking when transactions are enabled; I’m encountering weird problems with innodb that sound like they may be related. I can’t find anything that suggests actual locks being run into mysql. Did you find anything that explicitly mentions database-side locking?

Locking occurs when execution is halted and a transaction has started (as always).
So if you turn DB debugging on, the error is displayed and you can't perform a rollback. This is in commented in CI docs.


Doing what I proposed in my post, and turning DB debugging off, is what I'm doing for the moment. This way I have no problems with deadlocks.
I'll try to enhance this method, as a lot of not so critical errors are also shown on the log files.


I'm afraid that I'll have to get inside MySQL driver files, as you said, but I'll post any advance I make.


Regards.
#4

[eluser]xwero[/eluser]
If you going to change the driver you might want to read this first. It's a tutorial to update proof your custom database driver files.




Theme © iAndrew 2016 - Forum software by © MyBB