Skip to content

Instantly share code, notes, and snippets.

@yuka2py
Created October 26, 2012 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuka2py/3957781 to your computer and use it in GitHub Desktop.
Save yuka2py/3957781 to your computer and use it in GitHub Desktop.
appfogでDBへの接続情報を取得する
<?php
$services_json = getenv('VCAP_SERVICES');
$services = json_decode($services_json, true);
$config = null;
foreach ($services as $name => $service) {
if (0 === stripos($name, 'mysql')) {
$config = $service[0]['credentials'];
break;
}
}
is_null($config) && die('MySQL service information not found.');
$db_hostname = $config["hostname"];
$db_hostport = $config["port"];
$db_username = $config["user"];
$db_password = $config["password"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment