Created
April 12, 2012 18:10
-
-
Save lhitchon/2369742 to your computer and use it in GitHub Desktop.
PHP MySQL Test
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
<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