public static function create($titel, $genreId)
 {
     $bestaandBoek = self::getByTitel($titel);
     if (isset($bestaandBoek)) {
         throw new TitelBestaatException();
     }
     $sql = "INSERT INTO mvc_boeken (titel, genreid) VALUES ('" . $titel . "', " . $genreId . ")";
     $dbh = new PDO(DBConfig::$DB_CONNSTRING, DBConfig::$DB_USERNAME, DBConfig::$DB_PASSWORD);
     $dbh->exec($sql);
     $boekId = $dbh->lastInsertId();
     $dbh = NULL;
     $genre = GenreDAO::getById($genreId);
     $boek = Boek::create($boekId, $titel, $genre);
     return boek;
 }
Example #2
0
 public function create($titel, $genreId)
 {
     $dbh = new PDO(DBConfig::$DB_CONNSTRING, DBConfig::$DB_USERNAME, DBConfig::$DB_PASSWORD);
     $sql = "insert into mvc_boeken (titel, genre_id)  \n                    values (:titel, :genreId)";
     $stmt = $dbh->prepare($sql);
     $stmt->execute(array(':titel' => $titel, ':genreId' => $genreId));
     //id van de net ingevoerde boek
     $boekId = $dbh->lastInsertId();
     $dbh = null;
     //genre id ophalen voor het boek
     $genreDAO = new GenreDAO();
     $genre = $genreDAO->getById($genreId);
     //creer boek aan de hand van boekid,titel en genre
     $boek = Boek::create($boekId, $titel, $genre);
     return $boek;
 }
 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;
 }
Example #4
0
 public function getByTitel($titel)
 {
     $sql = "select mvc_boeken.id as boek_id, titel, genre_id, genre  \n\t\tfrom mvc_boeken, mvc_genres   \n\t\twhere genre_id = mvc_genres.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"]);
         $boek = Boek::create($rij["boek_id"], $rij["titel"], $genre);
         $dbh = null;
         return $boek;
     }
 }