Database config from environment variable mysql:// URL?

Hi folks,

Forgive me if I’m missing something obvious — I’m new to both PHP and Piwik. :slight_smile:

I’ve scoured this forum, Stack Overflow and Google but was unable to find an answer: is there a way to fetch the database config from environment variables? For example:

HEROKU_POSTGRESQL_GREEN_URL: postgres://user:pass@foo:5432/db_name
MYSQL_URL: mysql://user:pass@foo:3306/db_name

I saw this thread from a few weeks ago, but it doesn’t explain how to parse the env variable.

I’ve used this code to get WordPress working, and it appears to be working in my bootstrap.php, but I’m unable to get the variables working in the config.ini.php file.

$db_url = getenv('MYSQL_URI');
$db = parse_url($db_url);
$db_host = $db["host"];
$db_user = $db["user"];
$db_pass = $db["pass"];
$db_name = trim($db["path"], "/");

Thanks in advance,