Last active
March 1, 2023 11:29
-
-
Save dazecoop/233ddd4947790e280d6267b4113403c9 to your computer and use it in GitHub Desktop.
A few lines of code to manually test a WordPress database connection. Add below DB define's in your wp-config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Manually test WordPress database connection. Return useful errors upon failure. | |
*/ | |
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); | |
if ($mysqli->connect_errno) { | |
die("❌ Failed to connect to MySQL: {$mysqli->connect_error}"); | |
} | |
if ($result = $mysqli->query("SELECT * FROM `{$table_prefix}options`")) { | |
echo "✅ Connection OK. Returned rows are: {$result->num_rows}"; | |
$result->free_result(); | |
} | |
$mysqli->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment