You are here

public function LegacyPdoSessionHandler::read in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php \Symfony\Component\HttpFoundation\Session\Storage\Handler\LegacyPdoSessionHandler::read()

File

vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php, line 152

Class

LegacyPdoSessionHandler
Session handler using a PDO connection to read and write data.

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler

Code

public function read($sessionId) {
  $sql = "SELECT {$this->dataCol} FROM {$this->table} WHERE {$this->idCol} = :id";
  try {
    $stmt = $this->pdo
      ->prepare($sql);
    $stmt
      ->bindParam(':id', $sessionId, \PDO::PARAM_STR);
    $stmt
      ->execute();

    // We use fetchAll instead of fetchColumn to make sure the DB cursor gets closed
    $sessionRows = $stmt
      ->fetchAll(\PDO::FETCH_NUM);
    if ($sessionRows) {
      return base64_decode($sessionRows[0][0]);
    }
    return '';
  } catch (\PDOException $e) {
    throw new \RuntimeException(sprintf('PDOException was thrown when trying to read the session data: %s', $e
      ->getMessage()), 0, $e);
  }
}