Exemplo n.º 1
0
 protected function execute()
 {
     if ($this->rows !== NULL) {
         return;
     }
     $this->observeCache = TRUE;
     try {
         $result = $this->query($this->sqlBuilder->buildSelectQuery());
     } catch (PDOException $exception) {
         if (!$this->sqlBuilder->getSelect() && $this->prevAccessed) {
             $this->prevAccessed = '';
             $this->accessed = array();
             $result = $this->query($this->sqlBuilder->buildSelectQuery());
         } else {
             throw $exception;
         }
     }
     $this->rows = array();
     $result->setFetchMode(PDO::FETCH_ASSOC);
     foreach ($result as $key => $row) {
         $row = $result->normalizeRow($row);
         $this->rows[isset($row[$this->primary]) ? $row[$this->primary] : $key] = $this->createRow($row);
     }
     $this->data = $this->rows;
     if (isset($row[$this->primary]) && !is_string($this->accessed)) {
         $this->accessed[$this->primary] = TRUE;
     }
 }
Exemplo n.º 2
0
 private function load()
 {
     if ($this->id == NULL || $this->loaded) {
         return false;
     }
     $queryArgs = [];
     $query = SqlBuilder::buildSelectQuery($this->table, '*', ['id' => $this->id], $queryArgs);
     $params = self::execute($query, $queryArgs, 'single');
     foreach ($params as $column => $value) {
         $this->fields[$column] = $value;
     }
     $this->modified = false;
     $this->loaded = true;
     return true;
 }