function drush_sql_empty_db

6.x sql.drush.inc drush_sql_empty_db($db_spec)
4.x sql.drush.inc drush_sql_empty_db($db_spec = NULL)
5.x sql.drush.inc drush_sql_empty_db($db_spec = NULL)
2 calls to drush_sql_empty_db()
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.

File

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

Code

function drush_sql_empty_db($db_spec = NULL) {
  if (is_null($db_spec)) {
    $db_spec = _drush_sql_get_db_spec();
  }
  $sql = drush_sql_build_createdb_sql($db_spec, TRUE);
  // Get credentials to connect to the server, but not the database which we
  // are about to DROP. @see _drush_sql_get_credentials().
  $create_db_spec = $db_spec;
  unset($create_db_spec['database']);
  $create_db_su = drush_sql_su($create_db_spec);
  if (!_drush_sql_query($sql, $create_db_su)) {
    // If we could not drop the database, try instead to drop all
    // of the tables in the database (presuming it exists...).
    // If we cannot do either operation, then fail with an error.
    if (!_drush_sql_drop($db_spec)) {
      return drush_set_error(dt('Could not drop and create database: @name', array('@name' => $db_name)));
    }
  }
  return TRUE;
}