Created
September 25, 2013 09:24
-
-
Save thoward/6697170 to your computer and use it in GitHub Desktop.
Simple PHP app to test if the app can connect to a bound mysql instance, in a CloudFoundry environment.
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 | |
echo "<p>Testing the connection to the MySQL database.<p>"; | |
echo "<p>vcap: " . getenv("VCAP_SERVICES") . "</p>"; | |
$services_json = json_decode(getenv("VCAP_SERVICES"),true); | |
echo "<p>services: " . $services_json . '</p>'; | |
$mysql_config = $services_json["mysql-5.1"][0]["credentials"]; | |
$username = $mysql_config["username"]; | |
$password = $mysql_config["password"]; | |
$hostname = $mysql_config["hostname"]; | |
$port = $mysql_config["port"]; | |
$db = $mysql_config["name"]; | |
echo "<p>connection: " . $hostname . ', ' . $username . ', ' . $password . '</p>'; | |
$test = mysql_connect($hostname,$username,$password); | |
if(!$test) { | |
die('Could not connect: ' . mysql_error()); | |
} | |
echo 'Connected successfully'; | |
mysql_close($test); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment