function Connection::__construct

Same name in this branch
  1. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Connection.php \Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion\Connection::__construct()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Connection.php \Drupal\Core\Database\Driver\mysql\Connection::__construct()
  3. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php \Drupal\Core\Database\Driver\pgsql\Connection::__construct()
  4. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::__construct()
Same name in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::__construct()
  2. 9 core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
  3. 9 core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::__construct()
  4. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::__construct()
  5. 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::__construct()
  6. 10 core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
  7. 10 core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::__construct()
  8. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::__construct()
  9. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::__construct()
  10. 11.x core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
  11. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::__construct()
  12. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::__construct()

Constructs a \Drupal\Core\Database\Driver\sqlite\Connection object.

Overrides Connection::__construct

File

core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php, line 61

Class

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

Namespace

Drupal\Core\Database\Driver\sqlite

Code

public function __construct(\PDO $connection, array $connection_options) {
    // We don't need a specific PDOStatement class here, we simulate it in
    // static::prepare().
    $this->statementClass = NULL;
    parent::__construct($connection, $connection_options);
    // This driver defaults to transaction support, except if explicitly passed FALSE.
    $this->transactionSupport = $this->transactionalDDLSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] !== FALSE;
    $this->connectionOptions = $connection_options;
    // Attach one database for each registered prefix.
    $prefixes = $this->prefixes;
    foreach ($prefixes as &$prefix) {
        // Empty prefix means query the main database -- no need to attach anything.
        if (!empty($prefix)) {
            // Only attach the database once.
            if (!isset($this->attachedDatabases[$prefix])) {
                $this->attachedDatabases[$prefix] = $prefix;
                if ($connection_options['database'] === ':memory:') {
                    // In memory database use ':memory:' as database name. According to
                    // http://www.sqlite.org/inmemorydb.html it will open a unique
                    // database so attaching it twice is not a problem.
                    $this->query('ATTACH DATABASE :database AS :prefix', [
                        ':database' => $connection_options['database'],
                        ':prefix' => $prefix,
                    ]);
                }
                else {
                    $this->query('ATTACH DATABASE :database AS :prefix', [
                        ':database' => $connection_options['database'] . '-' . $prefix,
                        ':prefix' => $prefix,
                    ]);
                }
            }
            // Add a ., so queries become prefix.table, which is proper syntax for
            // querying an attached database.
            $prefix .= '.';
        }
    }
    // Regenerate the prefixes replacement table.
    $this->setPrefix($prefixes);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.