public function create($titel, $genreId)
 {
     $bestaandBoek = $this->getByTitel($titel);
     if (!is_null($bestaandBoek)) {
         throw new TitelBestaatException();
     }
     $sql = "insert into mvc_boeken (titel, genre_id) values (:titel, :genreId)";
     $dbh = new PDO(DBConfig::$DB_CONNSTRING, DBConfig::$DB_USERNAME, DBConfig::$DB_PASSWORD);
     $stmt = $dbh->prepare($sql);
     $stmt->execute(array(':titel' => $titel, ':genreId' => $genreId));
     $boekId = $dbh->lastInsertId();
     $dbh = null;
     $genreDAO = new GenreDAO();
     $genre = $genreDAO->getById($genreId);
     $boek = Boek::create($boekId, $titel, $genre);
     return $boek;
 }
示例#2
0
 public function getByTitel($titel)
 {
     $sql = "select mvc_boek.id as boek_id, titel, genre_id from mvc_boek, mvc_genre where genre_id = mvc_genre.id and titel = :titel";
     $dbh = new PDO(DBConfig::$DB_CONNSTRING, DBConfig::$DB_USERNAME, DBConfig::$DB_PASSWORD);
     $stmt = $dbh->prepare($sql);
     $stmt->execute(array(":titel" => $titel));
     $rij = $stmt->fetch(PDO::FETCH_ASSOC);
     if (!$rij) {
         return null;
     } else {
         $genre = Genre::create($rij["genre_id"], $rij["genre_id"]);
         $boek = Boek::create($rij["boek_id"], $rij["titel"], $genre);
         $dbh = null;
         return $boek;
     }
 }