function drush_sql_get_class

8.0.x sql.drush.inc drush_sql_get_class($db_spec = NULL)
7.x sql.drush.inc drush_sql_get_class($db_spec = NULL)
master sql.drush.inc drush_sql_get_class($db_spec = NULL)

Wrapper for drush_get_class; instantiates an driver-specific instance of SqlBase class.

Parameters

array $db_spec: If known, specify a $db_spec that the class can operate with.

Return value

Drush\Sql\SqlBase

Throws

\Drush\Sql\SqlException

20 calls to drush_sql_get_class()
DrupalBoot::bootstrap_drupal_database_has_table in lib/Drush/Boot/DrupalBoot.php
Test to see if the Drupal database has a specified table or tables.
drush_archive_dump in commands/core/archive.drush.inc
Command callback. Generate site archive file.
drush_archive_restore in commands/core/archive.drush.inc
Command callback. Restore web site(s) from a site archive file.
drush_core_pre_site_install in commands/core/site_install.drush.inc
Perform setup tasks for installation.
drush_core_site_install_version in commands/core/drupal/site_install_7.inc
Install Drupal 7

... See full list

File

commands/sql/sql.drush.inc, line 559
Drush sql commands

Code

function drush_sql_get_class($db_spec = NULL) {
  $database = drush_get_option('database', 'default');
  $target = drush_get_option('target', 'default');

  // Try a few times to quickly get $db_spec.
  if (!empty($db_spec)) {
    if (!empty($db_spec['driver'])) {
      return drush_get_class(array('Drush\Sql\Sql', 'Drupal\Driver\Database\\' . $db_spec['driver'] . '\Drush'), array($db_spec), array($db_spec['driver']));
    }
  }
  elseif ($url = drush_get_option('db-url')) {
    $url = is_array($url) ? $url[$database] : $url;
    $db_spec = drush_convert_db_from_db_url($url);
    $db_spec['db_prefix'] = drush_get_option('db-prefix');
    return drush_sql_get_class($db_spec);
  }
  elseif (($databases = drush_get_option('databases')) && (array_key_exists($database, $databases)) && (array_key_exists($target, $databases[$database]))) {
    $db_spec = $databases[$database][$target];
    return drush_sql_get_class($db_spec);
  }
  else {
    // No parameter or options provided. Determine $db_spec ourselves.
    if ($sqlVersion = drush_sql_get_version()) {
      if ($db_spec = $sqlVersion->get_db_spec()) {
        return drush_sql_get_class($db_spec);
      }
    }
  }

  throw new \Drush\Sql\SqlException('Unable to find a matching SQL Class. Drush cannot find your database connection details.');
}