DatabaseHandler class
Framework\Session\SaveHandlers\DatabaseHandler
Class DatabaseHandler.
```sql
CREATE TABLE `Sessions` (
`id` varchar(128) NOT NULL,
`timestamp` timestamp NOT NULL,
`data` blob NOT NULL,
`ip` varchar(45) NOT NULL, -- optional
`ua` varchar(255) NOT NULL, -- optional
PRIMARY KEY (`id`),
KEY `timestamp` (`timestamp`),
KEY `ip` (`ip`), -- optional
KEY `ua` (`ua`) -- optional
);
```
NOTE: As of PHP 8.4 the id column can be `char(32)`.
Extends Framework\Session\SaveHandler
Implements:
SessionUpdateTimestampHandlerInterface, SessionHandlerInterface
Defined in libraries/session/src/SaveHandlers/DatabaseHandler.php
Properties #
$database
Methods #
- close()
- -
- destroy()
- -
- gc()
- -
- getDatabase()
- -
- open()
- -
- read()
- -
- setDatabase()
- -
- updateTimestamp()
- -
- write()
- -
- addUserIdColumn()
- Adds the optional `user_id` column.
- addWhereMatchs()
- Adds the `WHERE $column = $value` clauses when matching IP or User-Agent.
- getColumn()
- Get a column name based on custom/default configs.
- getTable()
- Get the table name based on custom/default configs.
- lock()
- -
- prepareConfig()
- Prepare configurations to be used by the DatabaseHandler.
- unlock()
- -
- writeInsert()
- -
- writeUpdate()
- -
close()
destroy()
- $id
gc()
- $max_lifetime
getDatabase()
open()
- $path
- $name
read()
- $id
setDatabase()
- \Framework\Database\Database $database
updateTimestamp()
- $id
- $data
write()
- $id
- $data
addUserIdColumn()
Adds the optional `user_id` column.
- array $columns - The statement columns to insert/update
addWhereMatchs()
Adds the `WHERE $column = $value` clauses when matching IP or User-Agent.
- \Framework\Database\Manipulation\Delete|\Framework\Database\Manipulation\Select|\Framework\Database\Manipulation\Update $statement - The statement to add the WHERE clause
getColumn()
Get a column name based on custom/default configs.
- string $key - The columns config key
getTable()
Get the table name based on custom/default configs.
lock()
- string $id
prepareConfig()
Prepare configurations to be used by the DatabaseHandler.
- array $config - Custom configs The custom configs are: ```php $configs = [ // The name of the table used for sessions 'table' => 'Sessions', // The maxlifetime used for locking 'maxlifetime' => null, // Null to use the ini value of session.gc_maxlifetime // The custom column names as values 'columns' => [ 'id' => 'id', 'data' => 'data', 'timestamp' => 'timestamp', 'ip' => 'ip', 'ua' => 'ua', ], // Match IP? 'match_ip' => false, // Match User-Agent? 'match_ua' => false, // Independent of match_ip, save the initial IP in the ip column? 'save_ip' => false, // Independent of match_ua, save the initial User-Agent in the ua column? 'save_ua' => false, ]; ``` NOTE: The Database::connect configs was not shown.
unlock()
writeInsert()
- string $id
- string $data
writeUpdate()
- string $id
- string $data
Inherited methods #
-
__construct()fromFramework\Session\SaveHandler -
getConfig()fromFramework\Session\SaveHandler -
log()fromFramework\Session\SaveHandler -
setFingerprint()fromFramework\Session\SaveHandler -
hasSameFingerprint()fromFramework\Session\SaveHandler -
getMaxlifetime()fromFramework\Session\SaveHandler -
getIP()fromFramework\Session\SaveHandler -
getUA()fromFramework\Session\SaveHandler -
getKeySuffix()fromFramework\Session\SaveHandler -
validateId()fromFramework\Session\SaveHandler