/** * @param SqlSpecification $specification * @return \JoseCelano\Destinia\Domain\Hotel[] * @throws \Exception */ public function query($specification) { $this->connect(); $clauses = $specification->toSqlClauses(); $sql = sprintf("SELECT * FROM `hotel` WHERE %s;", $clauses); $result = mysqli_query($this->conn, $sql); $hotels = array(); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $hotel = new Hotel(new HotelId($row["id"]), $row["name"], $row["starts"], $row["standard_room_type"]); $hotels[] = $hotel; } } $this->closeConnection(); return $hotels; }
/** * @param SqlSpecification $specification * @return \JoseCelano\Destinia\Domain\Hotel[] * @throws \Exception */ public function query($specification) { $this->connect(); $clauses = $specification->toSqlClauses(); $sql = sprintf("SELECT * FROM `apartment` WHERE %s;", $clauses); $result = mysqli_query($this->conn, $sql); $apartments = array(); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $apartment = new Apartment(new ApartmentId($row["id"]), $row["name"], $row["num_flats"], $row["num_adults_per_flat"]); $apartments[] = $apartment; } } $this->closeConnection(); return $apartments; }