function Connection::createConnectionOptionsFromUrl

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
Same name and namespace in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl()
  2. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
  3. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::createConnectionOptionsFromUrl()
  4. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
  5. 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl()
  6. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()

Creates an array of database connection options from a URL.

@internal This method should only be called from \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo().

Parameters

string $url: The URL.

string $root: (deprecated) The root directory of the Drupal installation. Some database drivers, like for example SQLite, need this information.

Return value

array The connection options.

Overrides Connection::createConnectionOptionsFromUrl

File

core/modules/sqlite/src/Driver/Database/sqlite/Connection.php, line 444

Class

Connection
SQLite implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\sqlite\Driver\Database\sqlite

Code

public static function createConnectionOptionsFromUrl($url, $root) {
  if ($root !== NULL) {
    @trigger_error("Passing the \$root value to " . __METHOD__ . "() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287", E_USER_DEPRECATED);
  }
  $database = parent::createConnectionOptionsFromUrl($url, NULL);
  // A SQLite database path with two leading slashes indicates a system path.
  // Otherwise the path is relative to the Drupal root.
  $url_components = parse_url($url);
  if ($url_components['path'][0] === '/') {
    $url_components['path'] = substr($url_components['path'], 1);
  }
  $database['database'] = $url_components['path'];
  // User credentials and system port are irrelevant for SQLite.
  unset($database['username'], $database['password'], $database['port']);
  return $database;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.