예제 #1
0
 /**
  * Inserts a row inte the table pubs
  *
  * @param Pub $pub
  * @throws \DataBaseException
  * @throws \Exception
  */
 public function addPub(Pub $pub)
 {
     try {
         $stmt = $this->conn->prepare("INSERT INTO " . self::$table . " VALUES(?, ?, ?, ?)");
         if (!$stmt) {
             throw new \DataBaseException($this->conn->error);
         }
         $id = $pub->getId();
         $name = $pub->getName();
         $address = $pub->getAddress();
         $webpage = $pub->getWebpageURL();
         $stmt->bind_param("ssss", $id, $name, $address, $webpage);
         $stmt->execute();
     } catch (\DataBaseException $e) {
         if (\Settings::DEBUG_MODE) {
             throw $e;
         } else {
             error_log($e->getMessage() . "\n", 3, \Settings::ERROR_LOG);
             echo "Something went wrong when connecting to the database";
             die;
         }
     }
 }