public function PdoSessionHandler::read

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php, line 127

Class

PdoSessionHandler
PdoSessionHandler.

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler

Code

public function read($id) {

  // get table/columns
  $dbTable = $this->dbOptions['db_table'];
  $dbDataCol = $this->dbOptions['db_data_col'];
  $dbIdCol = $this->dbOptions['db_id_col'];
  try {
    $sql = "SELECT {$dbDataCol} FROM {$dbTable} WHERE {$dbIdCol} = :id";
    $stmt = $this->pdo
      ->prepare($sql);
    $stmt
      ->bindParam(':id', $id, \PDO::PARAM_STR);
    $stmt
      ->execute();

    // it is recommended to use fetchAll so that PDO can close the DB cursor
    // we anyway expect either no rows, or one row with one column. fetchColumn, seems to be buggy #4777
    $sessionRows = $stmt
      ->fetchAll(\PDO::FETCH_NUM);
    if (count($sessionRows) == 1) {
      return base64_decode($sessionRows[0][0]);
    }

    // session does not exist, create it
    $this
      ->createNewSession($id);
    return '';
  } catch (\PDOException $e) {
    throw new \RuntimeException(sprintf('PDOException was thrown when trying to read the session data: %s', $e
      ->getMessage()), 0, $e);
  }
}