/** * @param Hotel $hotel * @throws \Exception */ public function insert(Hotel $hotel) { $this->connect(); $id = mysqli_real_escape_string($this->conn, $hotel->getId()->getValue()); $name = mysqli_real_escape_string($this->conn, $hotel->getName()); $starts = mysqli_real_escape_string($this->conn, $hotel->getStarts()); $standardRoomType = mysqli_real_escape_string($this->conn, $hotel->getStandardRoomType()); $sql = sprintf("INSERT INTO `hotel` (`id`, `name`, `starts`, `standard_room_type`) VALUES ('%s', '%s', %d, '%s')", $id, $name, $starts, $standardRoomType); if (!mysqli_query($this->conn, $sql)) { throw new \Exception("Error: " . $sql . "SQL Error" . mysqli_error($this->conn)); } $this->closeConnection(); }
/** * @param Hotel $hotel */ public function delete(Hotel $hotel) { if (isset($this->hotels[$hotel->getId()->getValue()])) { unset($this->hotels[$hotel->getId()->getValue()]); } }