• My website keeps on going down frequently (one every week or so) showing my the regular Database connection error.

    After enabling the debug log I’ve got almost 853 PHP notices at the same second (all the notices are at [07-Jul-2023 07:46:46 UTC]). These first 654 notices are:
    PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/html/sitename/wp-includes/class-wpdb.php on line 2019.

    What I’ve tried so far: “I’ve searched for this error on stack overflow and some people said they got rid of by changing the host in the wp-config from localhost to 127.0.0.1” this solution didn’t work for me.

    And the rest notices are: PHP Notice: Function wpdb was called incorrectly. wpdb must set a database connection for use with escaping. Please see Debugging in WordPress for more information. (This message was added in version 3.6.0.) in /var/www/html/7awi/wp-includes/functions.php on line 5865.
    I don’t have any custom functions or custom plugins and everything is up to date

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    No such file or directory

    That’s kind of odd since mysqli_real_connect() accepts no file paths nor accesses any files. As its name suggests, it’s trying to connect to your DB server. I think the file error is because WP is trying to log an error to a file it doesn’t have permission to write to. The root cause is the connection attempt failed. All remaining messages are only side effects of the root cause.

    Apparently your DB connection credentials are correct since they work some of the time. Intermittent connection faults could indicate the DB server is overloaded. In any case, intermittent connection failures are an issue with the server’s configuration and you’ll need your host’s assistance to resolve it.

    IME having the host move your site to a different server will frequently resolve similar problems.

    Thread Starter ehab971

    (@ehab971)

    @bcworkz Thank you so much for the explanation.

    As this website is fairly big, I don’ think we can move it easily to another host. However, can you please explain more about this line your wrote?
    I think the file error is because WP is trying to log an error to a file it doesn’t have permission to write to.

    Can disabling the log completely fix the issue?
    This is what I have in wp-config.php for debugging

    define(‘WP_ALLOW_REPAIR’, false);
    define(‘DISABLE_WP_CRON’, true);
    // log PHP errors
    @ini_set(‘log_errors’,’On’); // enable or disable PHP error logging (use ‘On’ or ‘Off’)
    @ini_set(‘display_errors’,’Off’); // enable or disable public display of errors (use ‘On’ or ‘Off’)
    @ini_set(‘error_log’,’/var/www/html/site/php-errors.log’); // path to server-writable log file
    //another way to log
    define( ‘WP_DEBUG’, true );
    //define( ‘WP_DEBUG_LOG’, true );
    define( ‘WP_DEBUG_DISPLAY’, false );
    define(‘WP_MEMORY_LIMIT’, ‘256M’);
    //define(‘WP_MEMORY_LIMIT’, ‘256M’);
    //define(‘DISABLE_WP_CRON’, true);
    //define(‘CONCATENATE_SCRIPTS’, false);
    /* That’s all, stop editing! Happy publishing. / /* Absolute path to the WordPress directory. / if ( ! defined( ‘ABSPATH’ ) ) { define( ‘ABSPATH’, dirname( FILE ) . ‘/’ ); } /* Sets up WordPress vars and included files. */
    require_once( ABSPATH . ‘wp-settings.php’ );

    Moderator bcworkz

    (@bcworkz)

    Disabling the error log will only change the error messages you see on screen, if any. It will not resolve whatever the root cause is. My comment about not being able to write to the error log was only explaining why the error message was there. It doesn’t explain what causes the connection failure.

    The other messages about wpdb being used incorrectly are also because the connection failed. Resolve the connection problem and the messages will go away. It’s somewhat common for error messages to be misleading. They reflect the immediate issue encountered. The issue encountered is not necessarily the root cause of the problem.

    Intermittent problems are almost always related to server configuration and not WP itself. You’ll likely need your host’s assistance to resolve this. If they also have trouble isolating the problem, I recommend asking them if they could move your site to a different server. I wasn’t suggesting changing hosts, only servers. You’d only change hosts if you’re distinctly unhappy with the service provided.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function wpdb was called incorrectly wpdb must set a database connection’ is closed to new replies.