diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 819e671..1ee8889 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1018,6 +1018,10 @@ function install_settings_form($form, &$form_state, &$install_state) {
 function install_settings_form_validate($form, &$form_state) {
   $driver = $form_state['values']['driver'];
   $database = $form_state['values'][$driver];
+  $drivers = drupal_get_database_types();
+  if (strpos(get_class($drivers[$driver]), 'Drupal\\Core\\Database') !== 0) {
+    $database['custom'] = TRUE;
+  }
   $database['driver'] = $driver;
 
   // TODO: remove when PIFR will be updated to use 'db_prefix' instead of
@@ -1090,8 +1094,13 @@ function install_settings_form_submit($form, &$form_state) {
     'value'    => drupal_hash_base64(drupal_random_bytes(55)),
     'required' => TRUE,
   );
+  $extras = '';
+  if (!empty($form_state['storage']['database']['custom'])) {
+    $driver = $form_state['storage']['database']['driver'];
+    $extras = "drupal_classloader_register('$driver', \"db_drivers/$driver\");\n";
+  }
 
-  drupal_rewrite_settings($settings);
+  drupal_rewrite_settings($settings, $extras);
 
   // Add the config directories to settings.php.
   drupal_install_config_directories();
diff --git a/core/includes/install.inc b/core/includes/install.inc
index e9d666f..0c818fb 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -139,6 +139,16 @@ function drupal_get_database_types() {
       $drivers[$file->filename] = $file->uri;
     }
   }
+  if (is_dir(DRUPAL_ROOT . '/db_drivers')) {
+    $files = file_scan_directory(DRUPAL_ROOT . '/db_drivers', '/^[a-z_]+$/i', array('recurse' => FALSE));
+    foreach ($files as $uri => $file) {
+      $file->uri .= "/lib/Drupal/$file->filename";
+      if (file_exists($file->uri . '/Install/Tasks.php')) {
+        $drivers[$file->filename] = $file->uri;
+        drupal_classloader_register($file->filename, "db_drivers/$file->filename");
+      }
+    }
+  }
 
   foreach ($drivers as $driver => $file) {
     $installer = db_installer_object($driver);
@@ -162,8 +172,10 @@ function drupal_get_database_types() {
  *
  * @param $settings
  *   An array of settings that need to be updated.
+ * @param $extras
+ *   Additional code to be added to settings.php.
  */
-function drupal_rewrite_settings($settings = array()) {
+function drupal_rewrite_settings($settings = array(), $extras = '') {
   drupal_static_reset('conf_path');
   $settings_file = conf_path(FALSE) . '/settings.php';
 
@@ -213,6 +225,9 @@ function drupal_rewrite_settings($settings = array()) {
         $buffer .= "\$$setting = " . var_export($data['value'], TRUE) . ";\n";
       }
     }
+    if ($extras) {
+      $buffer .= "\n" . $extras;
+    }
 
     // Write the new settings file.
     if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) {
@@ -954,5 +969,11 @@ function db_installer_object($driver) {
   // We cannot use Database::getConnection->getDriverClass() here, because
   // the connection object is not yet functional.
   $task_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Install\\Tasks";
-  return new $task_class();
+  if (class_exists($task_class)) {
+    return new $task_class();
+  }
+  else {
+    $task_class = "Drupal\\{$driver}\\Install\\Tasks";
+    return new $task_class();
+  }
 }
diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index 51efaf4..53a92da 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -620,7 +620,12 @@ protected function expandArguments(&$query, &$args) {
   public function getDriverClass($class) {
     if (empty($this->driverClasses[$class])) {
       $driver = $this->driver();
-      $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\{$class}";
+      if (!empty($this->connectionOptions['custom'])) {
+        $driver_class  = "Drupal\\{$driver}\\{$class}";
+      }
+      else {
+        $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\{$class}";
+      }
       $this->driverClasses[$class] = class_exists($driver_class) ? $driver_class : $class;
     }
     return $this->driverClasses[$class];
diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php
index 25fe8fa..b8a5b8f 100644
--- a/core/lib/Drupal/Core/Database/Database.php
+++ b/core/lib/Drupal/Core/Database/Database.php
@@ -374,7 +374,12 @@ public static function addConnectionInfo($key, $target, $info) {
       throw new DriverNotSpecifiedException('Driver not specified for this database connection: ' . $key);
     }
 
-    $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection";
+    if (!empty(self::$databaseInfo[$key][$target]['custom'])) {
+      $driver_class = "Drupal\\{$driver}\\Connection";
+    }
+    else {
+      $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection";
+    }
     $new_connection = new $driver_class(self::$databaseInfo[$key][$target]);
     $new_connection->setTarget($target);
     $new_connection->setKey($key);
