You are here

function update_parse_db_url in Drupal 7

Parse pre-Drupal 7 database connection URLs and return D7 compatible array.

Return value

Drupal 7 DBTNG compatible array of database connection information.

2 calls to update_parse_db_url()
update_fix_d7_requirements in includes/update.inc
Perform Drupal 6.x to 7.x updates that are required for update.php to function properly.
update_prepare_d7_bootstrap in includes/update.inc
Performs extra steps required to bootstrap when using a Drupal 6 database.

File

includes/update.inc, line 863
Drupal database update API.

Code

function update_parse_db_url($db_url, $db_prefix) {
  $databases = array();
  if (!is_array($db_url)) {
    $db_url = array(
      'default' => $db_url,
    );
  }
  foreach ($db_url as $database => $url) {
    $url = parse_url($url);
    $databases[$database]['default'] = array(
      // MySQLi uses the mysql driver.
      'driver' => $url['scheme'] == 'mysqli' ? 'mysql' : $url['scheme'],
      // Remove the leading slash to get the database name.
      'database' => substr(urldecode($url['path']), 1),
      'username' => urldecode($url['user']),
      'password' => isset($url['pass']) ? urldecode($url['pass']) : '',
      'host' => urldecode($url['host']),
      'port' => isset($url['port']) ? urldecode($url['port']) : '',
    );
    if (isset($db_prefix)) {
      $databases[$database]['default']['prefix'] = $db_prefix;
    }
  }
  return $databases;
}