How to log mysql errors from wordpress core?

You should be using the wpdb class for all your own queries. All core queries also use wpdb. See wpdb Show and Hide SQL Errors

<?php $wpdb->show_errors(); ?> 
<?php $wpdb->hide_errors(); ?> 

You can also print the error (if any) generated by the most recent query with print_error.

<?php $wpdb->print_error(); ?>

Also see SAVEQUERIES constant for wp-config.php:

define('SAVEQUERIES', true);

usage example:

<?php
if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}
?>

There are also a number of helpful debugging plugins, like Debug Bar & Console. Search the WordPress plugin repository for this and other debugging related plugins.

Leave a Comment