W3cubDocs

/Drupal 8

function drupal_get_database_types

drupal_get_database_types()

Returns all supported database driver installer objects.

Return value

\Drupal\Core\Database\Install\Tasks[] An array of available database driver installer objects.

File

core/includes/install.inc, line 160
API functions for installing modules and themes.

Code

function drupal_get_database_types() {
  $databases = array();
  $drivers = array();

  // The internal database driver name is any valid PHP identifier.
  $mask = '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '$/';
  $files = file_scan_directory(DRUPAL_ROOT . '/core/lib/Drupal/Core/Database/Driver', $mask, array('recurse' => FALSE));
  if (is_dir(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database')) {
    $files += file_scan_directory(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database/', $mask, array('recurse' => FALSE));
  }
  foreach ($files as $file) {
    if (file_exists($file->uri . '/Install/Tasks.php')) {
      $drivers[$file->filename] = $file->uri;
    }
  }
  foreach ($drivers as $driver => $file) {
    $installer = db_installer_object($driver);
    if ($installer->installable()) {
      $databases[$driver] = $installer;
    }
  }

  // Usability: unconditionally put the MySQL driver on top.
  if (isset($databases['mysql'])) {
    $mysql_database = $databases['mysql'];
    unset($databases['mysql']);
    $databases = array('mysql' => $mysql_database) + $databases;
  }

  return $databases;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!install.inc/function/drupal_get_database_types/8.1.x