function Connection::open
Opens a client connection.
Parameters
array $connection_options: The database connection settings array.
Return value
object A client connection object.
Overrides Connection::open
4 calls to Connection::open()
- MigrateSqlIdMapTest::testGetQualifiedMapTablePrefix in core/
modules/ migrate/ tests/ src/ Unit/ MigrateSqlIdMapTest.php  - Tests the getQualifiedMapTable method with a prefixed database.
 - MigrateSqlSourceTestBase::getDatabase in core/
modules/ migrate/ tests/ src/ Kernel/ MigrateSqlSourceTestBase.php  - Builds an in-memory SQLite database from a set of source data.
 - MigrateTestCase::getDatabase in core/
modules/ migrate/ tests/ src/ Unit/ MigrateTestCase.php  - Gets an SQLite database connection object for use in tests.
 - QueryBatchTest::getDatabase in core/
modules/ migrate/ tests/ src/ Kernel/ QueryBatchTest.php  - Builds an in-memory SQLite database from a set of source data.
 
File
- 
              core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Connection.php, line 108  
Class
- Connection
 - SQLite implementation of \Drupal\Core\Database\Connection.
 
Namespace
Drupal\sqlite\Driver\Database\sqliteCode
public static function open(array &$connection_options = []) {
  // Allow PDO options to be overridden.
  $connection_options += [
    'pdo' => [],
  ];
  $connection_options['pdo'] += [
    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
    // Convert numeric values to strings when fetching.
\PDO::ATTR_STRINGIFY_FETCHES => TRUE,
  ];
  try {
    $pdo = new PDOConnection('sqlite:' . $connection_options['database'], '', '', $connection_options['pdo']);
  } catch (\PDOException $e) {
    if ($e->getCode() == static::DATABASE_NOT_FOUND) {
      throw new DatabaseNotFoundException($e->getMessage(), $e->getCode(), $e);
    }
    // SQLite doesn't have a distinct error code for access denied, so don't
    // deal with that case.
    throw $e;
  }
  // Create functions needed by SQLite.
  $pdo->sqliteCreateFunction('if', [
    __CLASS__,
    'sqlFunctionIf',
  ]);
  $pdo->sqliteCreateFunction('greatest', [
    __CLASS__,
    'sqlFunctionGreatest',
  ]);
  $pdo->sqliteCreateFunction('least', [
    __CLASS__,
    'sqlFunctionLeast',
  ]);
  $pdo->sqliteCreateFunction('pow', 'pow', 2);
  $pdo->sqliteCreateFunction('exp', 'exp', 1);
  $pdo->sqliteCreateFunction('length', 'strlen', 1);
  $pdo->sqliteCreateFunction('md5', 'md5', 1);
  $pdo->sqliteCreateFunction('concat', [
    __CLASS__,
    'sqlFunctionConcat',
  ]);
  $pdo->sqliteCreateFunction('concat_ws', [
    __CLASS__,
    'sqlFunctionConcatWs',
  ]);
  $pdo->sqliteCreateFunction('substring', [
    __CLASS__,
    'sqlFunctionSubstring',
  ], 3);
  $pdo->sqliteCreateFunction('substring_index', [
    __CLASS__,
    'sqlFunctionSubstringIndex',
  ], 3);
  $pdo->sqliteCreateFunction('rand', [
    __CLASS__,
    'sqlFunctionRand',
  ]);
  $pdo->sqliteCreateFunction('regexp', [
    __CLASS__,
    'sqlFunctionRegexp',
  ]);
  // SQLite does not support the LIKE BINARY operator, so we overload the
  // non-standard GLOB operator for case-sensitive matching. Another option
  // would have been to override another non-standard operator, MATCH, but
  // that does not support the NOT keyword prefix.
  $pdo->sqliteCreateFunction('glob', [
    __CLASS__,
    'sqlFunctionLikeBinary',
  ]);
  // Create a user-space case-insensitive collation with UTF-8 support.
  $pdo->sqliteCreateCollation('NOCASE_UTF8', [
    'Drupal\\Component\\Utility\\Unicode',
    'strcasecmp',
  ]);
  // Set SQLite init_commands if not already defined. Enable the Write-Ahead
  // Logging (WAL) for SQLite. See https://www.drupal.org/node/2348137 and
  // https://www.sqlite.org/wal.html.
  $connection_options += [
    'init_commands' => [],
  ];
  $connection_options['init_commands'] += [
    'wal' => "PRAGMA journal_mode=WAL",
  ];
  // Execute sqlite init_commands.
  if (isset($connection_options['init_commands'])) {
    $pdo->exec(implode('; ', $connection_options['init_commands']));
  }
  return $pdo;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.