function drush_sql_get_class

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

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


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

Return value




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/
Command callback. Generate site archive file.
drush_archive_restore in commands/core/
Command callback. Restore web site(s) from a site archive file.
drush_core_pre_site_install in commands/core/
Perform setup tasks for installation.
drush_core_site_install_version in commands/core/drupal/
Install Drupal 7

... See full list


commands/sql/, line 559
Drush sql commands


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.');