Created
February 1, 2012 12:49
-
-
Save otype/1716856 to your computer and use it in GitHub Desktop.
MYSQLD Example for reading out credentials
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
<?php | |
/** | |
* | |
* Every deployment gets different credentials for each Add-on. Providers | |
* can change these credentials at any time. It is therefore required to read | |
* the credentials from the provided JSON file to keep the application running | |
* in case the credentials change. | |
* | |
* The path to the JSON file can be found in the CRED_FILE environment variable. | |
* | |
*/ | |
# read the credentials file | |
$string = file_get_contents($_ENV['CRED_FILE'], false); | |
if ($string == false) { | |
die('FATAL: Could not read credentials file'); | |
} | |
# the file contains a JSON string, decode it and return an associative array | |
$creds = json_decode($string, true); | |
# use credentials to set the configuration for MySQL | |
$config = array( | |
'MYSQL_HOSTNAME' => $creds['MYSQLD']['MYSQLD_SERVER'], | |
'MYSQL_DATABASE' => $creds['MYSQLD']['MYSQLD_DATABASE'], | |
'MYSQL_USERNAME' => $creds['MYSQLD']['MYSQLD_USER'], | |
'MYSQL_PASSWORD' => $creds['MYSQLD']['MYSQLD_PASSWORD'] | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment