Example #1
0
 protected function getData($attributes)
 {
     $database = new Database();
     $db = $database->getInterface();
     $wheres = array();
     $columns = $this->reference->getColumns();
     $table = $this->reference->getTable();
     foreach ($attributes as $column => $value) {
         if (in_array($column, $columns)) {
             $wheres[] = $column . ' = :' . $column;
         } else {
             unset($attributes[$column]);
         }
     }
     $statement = 'SELECT ' . implode(',', $this->reference->getColumns()) . ' FROM ' . $table;
     if (count($wheres) > 0) {
         $statement .= ' WHERE ' . implode(' AND ', $wheres);
     }
     $statement .= $this->orderBy;
     if (isset($this->limit)) {
         $statement .= ' LIMIT :limit';
     }
     if (isset($this->offset)) {
         $statement .= ' OFFSET :offset';
     }
     $select = $database->getInterface()->prepare($statement);
     if (isset($this->limit)) {
         $select->bindValue(':limit', $this->limit, PDO::PARAM_INT);
     }
     if (isset($this->offset)) {
         $select->bindValue(':offset', $this->offset * $this->limit, PDO::PARAM_INT);
     }
     foreach ($attributes as $column => $value) {
         $select->bindValue(':' . $column, $value);
     }
     if ($select->execute()) {
         $database->killInterface();
         return $select->fetchAll(PDO::FETCH_ASSOC);
     } else {
         // error?
     }
     $database->killInterface();
     return array();
 }
Example #2
0
 public function delete()
 {
     $success = false;
     if (isset($this->attributes[$this->IDColumn])) {
         $database = new Database();
         $delete = $database->getInterface()->prepare('DELETE FROM ' . $this->table . ' WHERE ' . $this->IDColumn . ' = :id');
         $delete->bindValue(':id', $this->attributes[$this->IDColumn]);
         if ($delete->execute()) {
             $success = true;
         }
         $database->killInterface();
     }
     return $success;
 }