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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public static function getConnectionInfoAsUrl( $key = 'default' ) { $db_info = static ::getConnectionInfo( $key ); if ( $db_info [ 'default' ][ 'driver' ] == 'sqlite' ) { } 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.