Convert Database object into database URL string I've define my own database connection in my Drupal settings file as follow:

$databases['migrate']['default'] = array(
  'driver' =&gt; 'mysql',
  'database' =&gt; 'drupal',
  'username' =&gt; 'root',
  'password' =&gt; 'root',
  'host' =&gt; 'localhost',
  'prefix' =&gt; '',
);


To read that in Database object format, you can run:

drush eval 'print_r(Database::getConnectionInfo("default", "migrate"));'


And now I would like to have the string representation (similar to $db_url in Drupal 6) to use it in some drush commands on that database e.g. drush --db-url=${DB_URL} status.

So I would like to convert above Database array format into database URL string format (e.g. mysql://root:root@localhost/drupal).

Is there any easy way of doing that via function, PHP code or drush?



Additional info:


There is update_parse_db_url() function, but it's converting database connection URLs and return D7 compatible array.
Using Drush:

drush sa @site --with-db-url


Or, to isolate just the db-url:

drush sa @site --with-db-url --format=csv --fields=db-url --field-labels=0