Skip to content

Instantly share code, notes, and snippets.

@thoward
Created September 25, 2013 09:24
Show Gist options
  • Save thoward/6697170 to your computer and use it in GitHub Desktop.
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.
<?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