/** * Return the content of a cache record with <i>$key</i>. * * @param string $key * @return string|null * @throws \Exception */ public function fetch($key) { $query = "SELECT `Key`, `Value`, `Expired` FROM `" . $this->cacheTableName . "` WHERE `key`=?;"; /* @var $connection \PDO */ $connection = MDbConnection::dbConnection(); /* @var $stmt \PDOStatement */ $stmt = $connection->prepare($query); /* @var $result bool */ $result = $stmt->execute(array($key)); if ($result === false) { throw new \Exception(json_encode($stmt->errorInfo())); } $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); if (count($rows) <= 0) { return null; } $key = $rows[0]['Key']; $value = $rows[0]['Value']; $expired = $rows[0]['Expired']; if ($expired == -1 || $expired > time()) { return unserialize($value); } $this->delete($key); return null; }