Last active
September 5, 2018 06:49
-
-
Save GerB/6e6bceb8febb6e46739024ddf3dfd9cb to your computer and use it in GitHub Desktop.
Test if database connection to phpBB install can be made
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
<?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