57 lines
1003 B
PHP
Executable File
57 lines
1003 B
PHP
Executable File
<?php
|
|
|
|
namespace Vn\Web;
|
|
|
|
class DbSessionHandler implements SessionHandlerInterface
|
|
{
|
|
private $db;
|
|
|
|
function __construct ($db)
|
|
{
|
|
$this->db = $db;
|
|
}
|
|
|
|
function close ()
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
function destroy ($sessionId)
|
|
{
|
|
$db->query ('DELETE FROM userSession WHERE ssid = #', [$sessionId]);
|
|
return TRUE;
|
|
}
|
|
|
|
function gc ($maxLifeTime)
|
|
{
|
|
$db->query ('DELETE FROM userSession
|
|
WHERE lastUpdate < TIMESTAMPADD(SECOND, -#, NOW())',
|
|
[$maxLifeTime]
|
|
);
|
|
return TRUE;
|
|
}
|
|
|
|
function open ($savePath, $name)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
function read ($sessionId)
|
|
{
|
|
//$db->query ('DO GET_LOCK(#, 30)', [$sessionId]);
|
|
$sessionData = $db->getValue (
|
|
'SELECT data FROM userSession WHERE ssid = #', [$sessionId]);
|
|
return isset ($sessionData) ? $sessionData : '';
|
|
}
|
|
|
|
function write ($sessionId, $sessionData)
|
|
{
|
|
$db->query ('REPLACE INTO userSession SET ssid = #, data = #',
|
|
[$sessionId, $sessionData]);
|
|
//$db->query ('DO RELEASE_LOCK(#)', [$sessionId]);
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
?>
|