public function LegacyPdoSessionHandler::write in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php \Symfony\Component\HttpFoundation\Session\Storage\Handler\LegacyPdoSessionHandler::write()
File
- vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php, line 177
Class
- LegacyPdoSessionHandler
- Session handler using a PDO connection to read and write data.
Namespace
Symfony\Component\HttpFoundation\Session\Storage\Handler
Code
public function write($sessionId, $data) {
$encoded = base64_encode($data);
try {
$mergeSql = $this
->getMergeSql();
if (null !== $mergeSql) {
$mergeStmt = $this->pdo
->prepare($mergeSql);
$mergeStmt
->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$mergeStmt
->bindParam(':data', $encoded, \PDO::PARAM_STR);
$mergeStmt
->bindValue(':time', time(), \PDO::PARAM_INT);
$mergeStmt
->execute();
return true;
}
$updateStmt = $this->pdo
->prepare("UPDATE {$this->table} SET {$this->dataCol} = :data, {$this->timeCol} = :time WHERE {$this->idCol} = :id");
$updateStmt
->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$updateStmt
->bindParam(':data', $encoded, \PDO::PARAM_STR);
$updateStmt
->bindValue(':time', time(), \PDO::PARAM_INT);
$updateStmt
->execute();
if (!$updateStmt
->rowCount()) {
try {
$insertStmt = $this->pdo
->prepare("INSERT INTO {$this->table} ({$this->idCol}, {$this->dataCol}, {$this->timeCol}) VALUES (:id, :data, :time)");
$insertStmt
->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$insertStmt
->bindParam(':data', $encoded, \PDO::PARAM_STR);
$insertStmt
->bindValue(':time', time(), \PDO::PARAM_INT);
$insertStmt
->execute();
} catch (\PDOException $e) {
if (0 === strpos($e
->getCode(), '23')) {
$updateStmt
->execute();
}
else {
throw $e;
}
}
}
} catch (\PDOException $e) {
throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e
->getMessage()), 0, $e);
}
return true;
}