Wordpress Database connection error while connection is successful
Asked Answered
O

2

6

I have this weird error with my wordpress website.
Later I noticed I got an automated warning message about the plugin "Unyson", but the provided urls don't work.


When I access the main page I get this error:

Database connection error

At first I expected it to be the Database Connection settings in the wp_config.php file.

I double checked them as I tried to log in to the Admin panel. I got the error: One or more database tables are unavailable. The database may need to be repaired.

So I added define('WP_ALLOW_REPAIR', true); and ran the repair module. Which gave me the following result: All tables look okay

Because after each table it says: table is okay I have to conclude it can actually connect to the database?

I also renamed the plugins folder _plugins and removed the unyson plugin from the folder, but the error still remains.

Does any have an idea to fix this issue?

Ornithosis answered 9/3, 2021 at 19:10 Comment(1)
Please never provide textual question details as screenshots. We always want text as copy-pasted text.Horsehide
E
1

I suggest you to enable WordPress debugging by adding the following lines to your wp-config.php file which is located in the root directory your WordPress installation.

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);

This will log errors and warnings to a debug.log file and also show errors/warnings on the browser screen. The log file might provide more details about the database connection issue, including any specific error messages or database queries that are failing.

Erechtheus answered 7/5, 2024 at 5:47 Comment(0)
S
0

According to the explanation you provided, it sounds like the database connection is fine and since you've already disabled the "Unyson" plugin and you're still getting the "Error establishing a database connection". You need to enable WordPress debugging and disable PHP debugging in your wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0); 

This configures WordPress to write errors to a debug.log file within the wp-content directory, which you can check for errors, it avoids showing errors in your browser for security reason.

Just for you to be sure that the database connection is fine. You can test the database connection manually by creating a php file in your WordPress directory, you can name it anything e.g testdb.php

<?php
// your_database_host for most database is localhost by default
$link = mysqli_connect('your_database_host', 'your_username', 'your_password', 'your_database_name');

if (!$link) {
    die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);

If the database connection is fine and you're still getting the error, then something must be wrong with WordPress core files. You can restore the core files. To restore the WordPress core files, download a fresh copy of WordPress from the official website and upload all the files except for the wp-content folder and the wp-config.php file.

Socle answered 11/5, 2024 at 8:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.