Skip to content

Instantly share code, notes, and snippets.

@digininja
Created August 8, 2018 15:06
Show Gist options
  • Save digininja/c358c587c8cb87d8048d48b722bdf143 to your computer and use it in GitHub Desktop.
Save digininja/c358c587c8cb87d8048d48b722bdf143 to your computer and use it in GitHub Desktop.
Check for DVWA database connection issues
<?php
/*
Put this file in the root of the DVWA installation then access it through a browser.
*/
require_once "config/config.inc.php";
function var_dump_pre ($data) {
print "<pre>";
var_dump ($data);
print "</pre>";
}
print "These are the configuration options that will be use:<br />";
var_dump_pre ($_DVWA[ 'db_server' ]);
var_dump_pre ($_DVWA[ 'db_database' ]);
var_dump_pre ($_DVWA[ 'db_user' ]);
var_dump_pre ($_DVWA[ 'db_password' ]);
print "Connecting to the database<br />";
$conn = mysqli_connect( $_DVWA[ 'db_server' ], $_DVWA[ 'db_user' ], $_DVWA[ 'db_password' ] );
print "This is the result of the connection (NULL is bad)<br />";
var_dump_pre ($conn);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
print "Connection made OK, switching to the right database<br />";
$res = mysqli_select_db($conn, $_DVWA['db_database']);
if (!$res) {
die("Could not switch to database");
}
print "Closing connection<br />";
$conn->close();
print "Connection closed, all looks good";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment