Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dazecoop/233ddd4947790e280d6267b4113403c9 to your computer and use it in GitHub Desktop.
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
/**
* 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