Skip to content

Instantly share code, notes, and snippets.

@GerB
Last active September 5, 2018 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GerB/6e6bceb8febb6e46739024ddf3dfd9cb to your computer and use it in GitHub Desktop.
Save GerB/6e6bceb8febb6e46739024ddf3dfd9cb to your computer and use it in GitHub Desktop.
Test if database connection to phpBB install can be made
<?php
/*
* Test connection to phpbb database
*/
include ('config.php');
// Create connection
$connection = new mysqli($dbhost . ':'. $dbport, $dbuser, $dbpasswd);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
echo 'Connected to ' . $dbhost . ' with provided data in config file<br>' . "\n";
}
$db = $connection->select_db($dbname);
if ($result = $connection->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
if (empty($row[0])) {
exit('DB could not be selected');
}
printf("Selected database is %s.\n", $row[0]);
$result->close();
} else {
exit('Query could not be executed');
}
$connection->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment