public static Database::getConnectionInfoAsUrl($key = 'default')
Gets database connection info as a URL.
Parameters
string $key: (Optional) The database connection key.
Return value
string The connection info as a URL.
File
- core/lib/Drupal/Core/Database/Database.php, line 499
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\Database
Code
public static function getConnectionInfoAsUrl($key = 'default') { $db_info = static::getConnectionInfo($key); if ($db_info['default']['driver'] == 'sqlite') { $db_url = 'sqlite://localhost/' . $db_info['default']['database']; } else { $user = ''; if ($db_info['default']['username']) { $user = $db_info['default']['username']; if ($db_info['default']['password']) { $user .= ':' . $db_info['default']['password']; } $user .= '@'; } $db_url = $db_info['default']['driver'] . '://' . $user . $db_info['default']['host']; if (isset($db_info['default']['port'])) { $db_url .= ':' . $db_info['default']['port']; } $db_url .= '/' . $db_info['default']['database']; } if ($db_info['default']['prefix']['default']) { $db_url .= '#' . $db_info['default']['prefix']['default']; } return $db_url; }
Please login to continue.