38 $this->_sessionTable =
$resource->getTableName(
'session');
39 $this->connection =
$resource->getConnection();
51 if (!$this->connection) {
53 new Phrase(
"The write connection to the database isn't available. Please try again later.")
56 if (!$this->connection->isTableExists($this->_sessionTable)) {
58 new Phrase(
"The database storage table doesn't exist. Verify the table and try again.")
71 public function open($savePath, $sessionName)
92 public function read($sessionId)
95 $select = $this->connection->select()->from(
99 'session_id = :session_id' 101 $bind = [
'session_id' => $sessionId];
105 $decodedData = base64_decode(
$data,
true);
106 if ($decodedData !==
false) {
107 $data = $decodedData;
119 public function write($sessionId, $sessionData)
122 $bindValues = [
'session_id' => $sessionId];
123 $select = $this->connection->select()->from($this->_sessionTable)->where(
'session_id = :session_id');
124 $exists = $this->connection->fetchOne(
$select, $bindValues);
127 $sessionData = base64_encode($sessionData);
128 $bind = [
'session_expires' =>
time(),
'session_data' => $sessionData];
131 $this->connection->update($this->_sessionTable, $bind, [
'session_id=?' => $sessionId]);
133 $bind[
'session_id'] = $sessionId;
134 $this->connection->insert($this->_sessionTable, $bind);
147 $where = [
'session_id = ?' => $sessionId];
148 $this->connection->delete($this->_sessionTable, $where);
159 public function gc($maxLifeTime)
161 $where = [
'session_expires < ?' =>
time() - $maxLifeTime];
162 $this->connection->delete($this->_sessionTable, $where);
open($savePath, $sessionName)
write($sessionId, $sessionData)
__construct(\Magento\Framework\App\ResourceConnection $resource)