Created
January 15, 2018 14:57
-
-
Save xeron56/a02c519fef1f5305043b3bed7e8871ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$connectstr_dbhost = ''; | |
$connectstr_dbname = ''; | |
$connectstr_dbusername = ''; | |
$connectstr_dbpassword = ''; | |
foreach ($_SERVER as $key => $value) { | |
if (strpos($key, "MYSQLCONNSTR_localdb") !== 0) { | |
continue; | |
} | |
$connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $value); | |
$connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value); | |
$connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\\1", $value); | |
$connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\\1", $value); | |
} | |
$link = mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname); | |
if (!$link) { | |
echo "Error: Unable to connect to MySQL." . PHP_EOL; | |
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; | |
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; | |
exit; | |
} | |
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; | |
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; | |
mysqli_close($link); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment