Exemplo n.º 1
0
 /**
  * Gets all the posts from the beer-table
  *
  * @return BeerRepository
  * @throws \DataBaseException
  * @throws \Exception
  */
 public function getBeers()
 {
     try {
         $stmt = $this->conn->prepare("SELECT * FROM " . self::$table);
         if ($stmt === FALSE) {
             throw new \DataBaseException($this->conn->error);
         }
         $stmt->execute();
         $stmt->bind_result($id, $name, $abv, $manufacturer, $imageURL, $country, $volume, $servingType);
         $ret = new BeerRepository();
         while ($stmt->fetch()) {
             $ret->add(new Beer($name, $abv, $manufacturer, $country, $volume, $servingType, $imageURL, $id));
         }
         return $ret;
     } catch (\DataBaseException $e) {
         error_log($e->getMessage() . "\n", 3, \Settings::ERROR_LOG);
         if (\Settings::DEBUG_MODE) {
             echo $e->getMessage();
             throw $e;
         } else {
             echo "Something went wrong when connecting to the database";
             //show error msg
             die;
         }
     }
 }
Exemplo n.º 2
0
 public function getBeers()
 {
     return $this->beers->get();
 }