Welcome Guest, Not a member yet? Register   Sign In
Unable to log failed MySQL queries
#1

I'm trying to log all MySQL queries using the DBQuery event. My setup:
PHP Code:
Events::on('DBQuery''\App\Libraries\Logger::logQuery'); 

My log function:

PHP Code:
public static function logQuery(\CodeIgniter\Database\Query $query)
{
    $q $query->getQuery();
    log_message('debug'"logQuery: ".$q);

The CI4 documentation indicates "This event is triggered whenever a new query has been run, whether successful or not." That doesn't seem to be the case! If a query fails the event never gets triggered, instead CodeIgniter's exception is triggered and that is what gets output to the error log. Their backtrace does not include the full query but rather a truncated one where args are displayed. For example:
CRITICAL - 2021-06-28 12:41:43 --> Table 'users.email' doesn't exist
#0 /Users/eddy/Sites/rsi-now/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php(329): mysqli->query('SELECT * FROM `...')
Is the documentation wrong? Or if not, how would I be able to log failed queries in their entirety?

Reply




Theme © iAndrew 2016 - Forum software by © MyBB