public function Sqlmysql::createdb_sql

8.0.x Sqlmysql.php public Sqlmysql::createdb_sql($dbname, $quoted = FALSE)
7.x Sqlmysql.php public Sqlmysql::createdb_sql($dbname, $quoted = FALSE)
master Sqlmysql.php public Sqlmysql::createdb_sql($dbname, $quoted = FALSE)

Build a SQL string for dropping and creating a database.

Parameters

string dbname: The database name.

boolean $quoted: Quote the database name. Mysql uses backticks to quote which can cause problems in a Windows shell. Set TRUE if the CREATE is not running on the bash command line.

Overrides SqlBase::createdb_sql

File

lib/Drush/Sql/Sqlmysql.php, line 57

Namespace

Drush\Sql

Class

Sqlmysql

Code

public function createdb_sql($dbname, $quoted = FALSE) {
  if ($quoted) {
    $dbname = '`' . $dbname . '`';
  }
  $sql[] = sprintf('DROP DATABASE IF EXISTS %s;', $dbname);
  $sql[] = sprintf('CREATE DATABASE %s /*!40100 DEFAULT CHARACTER SET utf8 */;', $dbname);
  $db_superuser = drush_get_option('db-su');
  if (isset($db_superuser)) {
    $sql[] = sprintf('GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@\'%%\'', $dbname, $this->db_spec['username']);
    $sql[] = sprintf("IDENTIFIED BY '%s';", $this->db_spec['password']);
    $sql[] = 'FLUSH PRIVILEGES;';
  }
  return implode(' ', $sql);
}