\Symfony\Component\HttpFoundation\Session\Storage\HandlerLegacyPdoSessionHandler

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

Session data is a binary string that can contain non-printable characters like the null byte. For this reason this handler base64 encodes the data to be able to save it in a character column.

This version of the PdoSessionHandler does NOT implement locking. So concurrent requests to the same session can result in data loss due to race conditions.

Summary

Methods
Properties
Constants
__construct()
open()
close()
destroy()
gc()
read()
write()
No public properties found
No constants found
getConnection()
No protected properties found
N/A
getMergeSql()
$pdo
$table
$idCol
$dataCol
$timeCol
N/A

Properties

$pdo

$pdo : \PDO

Type

\PDO — PDO instance

$table

$table : string

Type

string — Table name

$idCol

$idCol : string

Type

string — Column for session id

$dataCol

$dataCol : string

Type

string — Column for session data

$timeCol

$timeCol : string

Type

string — Column for timestamp

Methods

__construct()

__construct(\PDO  $pdo, array  $dbOptions = array()) 

Constructor.

List of available options:

  • db_table: The name of the table [required]
  • 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_time_col: The column where to store the timestamp [default: sess_time]

Parameters

\PDO $pdo

A \PDO instance

array $dbOptions

An associative array of DB options

Throws

\InvalidArgumentException

When "db_table" option is not provided

open()

open(string  $savePath, string  $sessionName) : boolean

Re-initializes existing session, or creates a new one.

Parameters

string $savePath

Save path

string $sessionName

Session name, see http://php.net/function.session-name.php

Returns

boolean —

true on success, false on failure

close()

close() : boolean

Closes the current session.

Returns

boolean —

true on success, false on failure

destroy()

destroy(string  $sessionId) : boolean

Destroys a session.

Parameters

string $sessionId

Session ID, see http://php.net/function.session-id

Returns

boolean —

true on success, false on failure

gc()

gc(string|integer  $maxlifetime) : boolean

Cleans up expired sessions (garbage collection).

Parameters

string|integer $maxlifetime

Sessions that have not updated for the last maxlifetime seconds will be removed

Returns

boolean —

true on success, false on failure

read()

read(string  $sessionId) : string

Reads the session data.

Parameters

string $sessionId

Session ID, see http://php.net/function.session-id

Returns

string —

Same session data as passed in write() or empty string when non-existent or on failure

write()

write(string  $sessionId, string  $data) : boolean

Writes the session data to the storage.

Care, the session ID passed to write() can be different from the one previously received in read() when the session ID changed due to session_regenerate_id().

Parameters

string $sessionId

Session ID , see http://php.net/function.session-id

string $data

Serialized session data to save

Returns

boolean —

true on success, false on failure

getConnection()

getConnection() : \PDO

Return a PDO instance

Returns

\PDO

getMergeSql()

getMergeSql() : string|null

Returns a merge/upsert (i.e. insert or update) SQL query when supported by the database.

Returns

string|null —

The SQL string or null when not supported