2016-09-19 06:40:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Vn\Web;
|
|
|
|
|
2016-09-23 22:47:34 +00:00
|
|
|
class DbSessionHandler implements \SessionHandlerInterface
|
2016-09-19 06:40:18 +00:00
|
|
|
{
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
function __construct ($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
function close ()
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function destroy ($sessionId)
|
|
|
|
{
|
2016-09-23 22:47:34 +00:00
|
|
|
$this->db->query ('DELETE FROM userSession WHERE ssid = #', [$sessionId]);
|
2016-09-19 06:40:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gc ($maxLifeTime)
|
|
|
|
{
|
2016-09-23 22:47:34 +00:00
|
|
|
$this->db->query ('DELETE FROM userSession
|
2016-09-20 18:36:22 +00:00
|
|
|
WHERE lastUpdate < TIMESTAMPADD(SECOND, -#, NOW())',
|
2016-09-19 06:40:18 +00:00
|
|
|
[$maxLifeTime]
|
|
|
|
);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function open ($savePath, $name)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function read ($sessionId)
|
|
|
|
{
|
2016-09-20 18:36:22 +00:00
|
|
|
//$db->query ('DO GET_LOCK(#, 30)', [$sessionId]);
|
2016-09-23 22:47:34 +00:00
|
|
|
$sessionData = $this->db->getValue (
|
2016-09-20 18:36:22 +00:00
|
|
|
'SELECT data FROM userSession WHERE ssid = #', [$sessionId]);
|
2016-09-19 06:40:18 +00:00
|
|
|
return isset ($sessionData) ? $sessionData : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function write ($sessionId, $sessionData)
|
|
|
|
{
|
2016-09-23 22:47:34 +00:00
|
|
|
$this->db->query ('REPLACE INTO userSession SET ssid = #, data = #',
|
2016-09-19 06:40:18 +00:00
|
|
|
[$sessionId, $sessionData]);
|
2016-09-20 18:36:22 +00:00
|
|
|
//$db->query ('DO RELEASE_LOCK(#)', [$sessionId]);
|
2016-09-19 06:40:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|