コード例 #1
0
 /**
  * @param Apartment $apartment
  * @throws \Exception
  */
 public function insert(Apartment $apartment)
 {
     $this->connect();
     $id = mysqli_real_escape_string($this->conn, $apartment->getId()->getValue());
     $name = mysqli_real_escape_string($this->conn, $apartment->getName());
     $numFlats = mysqli_real_escape_string($this->conn, $apartment->getNumFlats());
     $numAdultsPerFlat = mysqli_real_escape_string($this->conn, $apartment->getNumAdultsPerFlat());
     $sql = sprintf("INSERT INTO `apartment` (`id`, `name`, `num_flats`, `num_adults_per_flat`) VALUES ('%s', '%s', %d, '%s')", $id, $name, $numFlats, $numAdultsPerFlat);
     if (!mysqli_query($this->conn, $sql)) {
         throw new \Exception("Error: " . $sql . "SQL Error" . mysqli_error($this->conn));
     }
     $this->closeConnection();
 }
コード例 #2
0
 /**
  * @param Apartment $apartment
  */
 public function delete(Apartment $apartment)
 {
     if (isset($this->apartments[$apartment->getId()->getValue()])) {
         unset($this->apartments[$apartment->getId()->getValue()]);
     }
 }