You are here

public function Connection::__construct in Drupal 8

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

Constructs a Connection object.

Parameters

\PDO $connection: An object of the PDO class representing a database connection.

array $connection_options: An array of options for the connection. May include the following:

  • prefix
  • namespace
  • Other driver-specific options.
3 calls to Connection::__construct()
Connection::__construct in core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
Constructs a \Drupal\Core\Database\Driver\sqlite\Connection object.
Connection::__construct in core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
Constructs a connection object.
Connection::__construct in core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
Constructs a Connection object.
3 methods override Connection::__construct()
Connection::__construct in core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
Constructs a \Drupal\Core\Database\Driver\sqlite\Connection object.
Connection::__construct in core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
Constructs a connection object.
Connection::__construct in core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
Constructs a Connection object.

File

core/lib/Drupal/Core/Database/Connection.php, line 177

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function __construct(\PDO $connection, array $connection_options) {

  // Initialize and prepare the connection prefix.
  $this
    ->setPrefix(isset($connection_options['prefix']) ? $connection_options['prefix'] : '');

  // Set a Statement class, unless the driver opted out.
  if (!empty($this->statementClass)) {
    $connection
      ->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [
      $this->statementClass,
      [
        $this,
      ],
    ]);
  }
  $this->connection = $connection;
  $this->connectionOptions = $connection_options;
}