You are here

public function Connection::createDatabase in Drupal driver for SQL Server and SQL Azure 3.1.x

Same name and namespace in other branches
  1. 4.2.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::createDatabase()
  2. 4.0.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::createDatabase()
  3. 4.1.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::createDatabase()

Creates a database.

In order to use this method, you must be connected without a database specified.

Parameters

string $database: The name of the database to create.

Overrides Connection::createDatabase

File

src/Driver/Database/sqlsrv/Connection.php, line 218

Class

Connection
Sqlsvr implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\sqlsrv\Driver\Database\sqlsrv

Code

public function createDatabase($database) {

  // Escape the database name.
  $database = Database::getConnection()
    ->escapeDatabase($database);
  try {

    // Create the database and set it as active.
    $this->connection
      ->exec("CREATE DATABASE {$database}");
  } catch (DatabaseException $e) {
    throw new DatabaseNotFoundException($e
      ->getMessage());
  }
}