drupal_detect_database_types

Versions
5 – 7
drupal_detect_database_types()

Detect all supported databases that are compiled into PHP.

Return value

An array of database types compiled into PHP.

▾ 2 functions call drupal_detect_database_types()

install_database_errors in ./install.php
Check a database connection and return any errors.
install_settings_form in ./install.php
Installation task; define a form to configure and rewrite settings.php.

Code

includes/install.inc, line 207

<?php
function drupal_detect_database_types() {
  $databases = array();

  // We define a driver as a directory in /includes/database that in turn
  // contains a database.inc file. That allows us to drop in additional drivers
  // without modifying the installer.
  // Because we have no registry yet, we need to also include the install.inc
  // file for the driver explicitly.
  require_once DRUPAL_ROOT . '/includes/database/database.inc';
  foreach (file_scan_directory(DRUPAL_ROOT . '/includes/database', '/^[a-z]*$/i', array('recurse' => FALSE)) as $file) {
    include_once "{$file->uri}/install.inc";
    include_once "{$file->uri}/database.inc";
    $drivers[$file->filename] = $file->uri;
  }

  foreach ($drivers as $driver => $file) {
    $class = 'DatabaseTasks_' . $driver;
    $installer = new $class();
    if ($installer->installable()) {
      $databases[$driver] = $installer->name();
    }
  }

  // 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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.