Created
June 10, 2013 11:32
-
-
Save skopp/5748127 to your computer and use it in GitHub Desktop.
uhuru vcap sql
This file contains hidden or 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
/* uhuru vcap | |
Hello You should not use credentials from your tunnel session in the cloud. After you delete the tunnel, that credentials get deleted. */ | |
The way to do it, is read mysql connection details from the environment variable VCAP_SERVICES like this: | |
$services = getenv("VCAP_SERVICES"); | |
$services_json = json_decode($services,true); | |
$mysql_config = $services_json["mysql-5.1"][0]["credentials"]; | |
define('DB_NAME', $mysql_config["name"]); | |
define('DB_USER', $mysql_config["user"]); | |
define('DB_PASSWORD', $mysql_config["password"]); | |
define('DB_HOST', $mysql_config["hostname"]); | |
define('DB_PORT', $mysql_config["port"]); | |
For WebsiteBaker, you would need to edit the install/index.php file, to read data from that env variable. I managed to get it running adding some lines of code: | |
(..) | |
if(!defined('SESSION_STARTED')) { | |
session_name('wb_session_id'); | |
session_start(); | |
define('SESSION_STARTED', true); | |
} | |
$services = getenv("VCAP_SERVICES"); | |
$services_json = json_decode($services,true); | |
$mysql_config = $services_json["mysql-5.1"][0]["credentials"]; | |
$_SESSION['database_host'] = $mysql_config["hostname"]; | |
$_SESSION['database_username'] = $mysql_config["user"]; | |
$_SESSION['database_password'] = $mysql_config["password"]; | |
$_SESSION['database_name'] = $mysql_config["name"]; | |
$mod_path = dirname(str_replace('\\', '/', __FILE__)); | |
$doc_root = rtrim(realpath($_SERVER['DOCUMENT_ROOT']),'/'); | |
$mod_name = basename($mod_path); | |
$wb_path = dirname(dirname(realpath( __FILE__))); | |
(...) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment