hedera-web/vn/web/db-session-handler.php

58 lines
996 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 id = #', [$sessionId]);
return TRUE;
}
function gc ($maxLifeTime)
{
$db->query ('DELETE FROM userSession
WHERE creationDate < 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 id = #', [$sessionId]);
return isset ($sessionData) ? $sessionData : '';
}
function write ($sessionId, $sessionData)
{
$db->query ('REPLACE INTO userSession SET id = #, data = #',
[$sessionId, $sessionData]);
$db->query ('DO RELEASE_LOCK(#)', [$sessionId]);
return TRUE;
}
}
?>