/** * 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; } } }
public function getBeers() { return $this->beers->get(); }