Ejemplo n.º 1
0
 /**
  * Serves for finding posts
  *
  * @param string $id
  * @return array
  */
 static function find($id = 'all')
 {
     $db = ActiveRecord::getDbConnection();
     $table = static::getTable();
     if ($id == 'all') {
         $result = [];
         $query = $db->prepare("SELECT * FROM {$table} ORDER BY id");
         $query->execute();
         while ($row = $query->fetchObject()) {
             array_push($result, $row);
         }
     } else {
         $query = $db->prepare("SELECT * FROM {$table} WHERE id = :id");
         $query->execute([':id' => $id]);
         $result = $query->fetchObject();
     }
     return $result;
 }