Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Database.php

function Database::getConnectionInfoAsUrl

Gets database connection info as a URL.

Parameters

string $key: (Optional) The database connection key.

Return value

string The connection info as a URL.

Throws

\RuntimeException When the database connection is not defined.

1 call to Database::getConnectionInfoAsUrl()
PhpUnitTestRunner::runCommand in core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
Executes the PHPUnit command.

File

core/lib/Drupal/Core/Database/Database.php, line 601

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 (empty($db_info) || empty($db_info['default'])) {
        throw new \RuntimeException("Database connection {$key} not defined or missing the 'default' settings");
    }
    $namespace = $db_info['default']['namespace'];
    // Add the module name to the connection options to make it easy for the
    // connection class's createUrlFromConnectionOptions() method to add it to
    // the URL.
    $db_info['default']['module'] = explode('\\', $namespace)[1];
    $connection_class = $namespace . '\\Connection';
    return $connection_class::createUrlFromConnectionOptions($db_info['default']);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal