예제 #1
0
 /**
  * Load a value from cache.
  *
  * @param  string $id
  * @param  string $time
  * @return mixed
  */
 public function load($id, $time)
 {
     $value = false;
     // Determine if the value already exists.
     $rows = [];
     $this->prepare("SELECT * FROM " . $this->table . " WHERE id = :id")->bindParams(['id' => sha1($id)])->execute();
     if ($this->isPdo) {
         while (($row = $this->result->fetchAll(\PDO::FETCH_ASSOC)) != false) {
             $rows[] = $row;
         }
     } else {
         while (($row = $this->result->fetchArray(SQLITE3_ASSOC)) != false) {
             $rows[] = $row;
         }
     }
     // If the value is found, check expiration and return.
     if (count($rows) > 0) {
         $data = $rows[0]['value'];
         $timestamp = $rows[0]['time'];
         if ($timestamp == 0 || time() - $timestamp <= $time) {
             $value = unserialize($data);
         }
     }
     return $value;
 }
예제 #2
0
 /**
  * Get the all records as an associative array with fields names as keys.
  *
  * @return array()
  * @access public
  */
 public function getAll($fetchMode = PDO::FETCH_BOTH, $column = 0)
 {
     if ($fetchMode & PDO::FETCH_COLUMN > 0) {
         return $this->_result->fetchAll($fetchMode, $column);
     } else {
         return $this->_result->fetchAll($fetchMode);
     }
 }
예제 #3
0
파일: Sqlite.php 프로젝트: popphp/pop-cache
 /**
  * Get the lifetime of the value.
  *
  * @param  string $id
  * @return int
  */
 public function getLifetime($id)
 {
     // Determine if the value already exists.
     $rows = [];
     $value = 0;
     $this->prepare('SELECT * FROM "' . $this->table . '" WHERE "id" = :id')->bindParams(['id' => sha1($id)])->execute();
     if ($this->isPdo) {
         while (($row = $this->result->fetchAll(\PDO::FETCH_ASSOC)) != false) {
             $rows[] = $row;
         }
     } else {
         while (($row = $this->result->fetchArray(SQLITE3_ASSOC)) != false) {
             $rows[] = $row;
         }
     }
     // If the value is found, check expiration and return.
     if (count($rows) > 0) {
         $cacheValue = $rows[0];
         $value = $cacheValue['lifetime'];
     }
     return $value;
 }
예제 #4
0
 /**
  * Instantiates an SQLiteResult object from a query.
  * 
  * @param string $result A PDOStatement object.
  * @param int $resultType Controls how the row(s) will be returned.
  */
 public function __construct($result, $resultType = self::RESULT_OBJ)
 {
     $this->result = $result;
     $this->data = $this->result->fetchAll($resultType);
     $this->numRows = count($this->data);
 }