Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PdoSessionHandler.php

function PdoSessionHandler::__construct

You can either pass an existing database connection as PDO instance or pass a DSN string that will be used to lazy-connect to the database when the session is actually used. Furthermore it's possible to pass null which will then use the session.save_path ini setting as PDO DSN parameter.

List of available options:

  • db_table: The name of the table [default: sessions]
  • db_id_col: The column where to store the session id [default: sess_id]
  • db_data_col: The column where to store the session data [default: sess_data]
  • db_lifetime_col: The column where to store the lifetime [default: sess_lifetime]
  • db_time_col: The column where to store the timestamp [default: sess_time]
  • db_username: The username when lazy-connect [default: '']
  • db_password: The password when lazy-connect [default: '']
  • db_connection_options: An array of driver-specific connection options [default: []]
  • lock_mode: The strategy for locking, see constants [default: LOCK_TRANSACTIONAL]
  • ttl: The time to live in seconds.

Parameters

\PDO|string|null $pdoOrDsn A \PDO instance or DSN string or URL string or null:

Throws

\InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION

File

vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php, line 154

Class

PdoSessionHandler
Session handler using a PDO connection to read and write data.

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler

Code

public function __construct(\PDO|string|null $pdoOrDsn = null, array $options = []) {
    if ($pdoOrDsn instanceof \PDO) {
        if (\PDO::ERRMODE_EXCEPTION !== $pdoOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
            throw new \InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__));
        }
        $this->pdo = $pdoOrDsn;
        $this->driver = $this->pdo
            ->getAttribute(\PDO::ATTR_DRIVER_NAME);
    }
    elseif (\is_string($pdoOrDsn) && str_contains($pdoOrDsn, '://')) {
        $this->dsn = $this->buildDsnFromUrl($pdoOrDsn);
    }
    else {
        $this->dsn = $pdoOrDsn;
    }
    $this->table = $options['db_table'] ?? $this->table;
    $this->idCol = $options['db_id_col'] ?? $this->idCol;
    $this->dataCol = $options['db_data_col'] ?? $this->dataCol;
    $this->lifetimeCol = $options['db_lifetime_col'] ?? $this->lifetimeCol;
    $this->timeCol = $options['db_time_col'] ?? $this->timeCol;
    $this->username = $options['db_username'] ?? $this->username;
    $this->password = $options['db_password'] ?? $this->password;
    $this->connectionOptions = $options['db_connection_options'] ?? $this->connectionOptions;
    $this->lockMode = $options['lock_mode'] ?? $this->lockMode;
    $this->ttl = $options['ttl'] ?? null;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal