Skip to content

Instantly share code, notes, and snippets.

@lhitchon
Created April 12, 2012 18:10
Show Gist options
  • Save lhitchon/2369742 to your computer and use it in GitHub Desktop.
Save lhitchon/2369742 to your computer and use it in GitHub Desktop.
PHP MySQL Test
<h1>Test MySQL Connection</h1>
<?php
$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
// ** MySQL settings from resource descriptor ** //
$username = $mysql_config["username"];
$password = $mysql_config["password"];
$database = $mysql_config["name"];
$hostname = $mysql_config["hostname"];
$port = $mysql_config["port"];
?>
<pre><?php echo $username ?></pre>
<pre><?php echo $password ?></pre>
<pre><?php echo $database ?></pre>
<pre><?php echo $hostname ?></pre>
<pre><?php echo $port ?></pre>
<pre>
<?php
$host = $hostname;
$db = mysql_connect( $host, $username, $password);
if ( !$db ) {
echo "Unable to connect to " . $host;
} else {
echo "Connected!";
}
?>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment