From 1aafd18ccd1d17d12a21f2ebe48480183e088e96 Mon Sep 17 00:00:00 2001 From: "steve.maingana" Date: Sun, 14 Sep 2025 22:19:37 +0200 Subject: [PATCH] Branche classes --- controleur/LivreControleur.php | 24 ++++++++++++++++++++++++ controleur/afficherLivres.php | 4 ++-- controleur/ajouterLivre.php | 4 ++-- controleur/classes/Database.php | 0 controleur/classes/Livre.php | 14 -------------- controleur/classes/LivreControleur.php | 3 --- donnees/Database.php | 20 ++++++++++++++++++++ modele/Livre.php | 26 ++++++++++++++++++++++++++ modele/livres.php | 1 - test.php | 6 ++++++ 10 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 controleur/LivreControleur.php delete mode 100644 controleur/classes/Database.php delete mode 100644 controleur/classes/Livre.php delete mode 100644 controleur/classes/LivreControleur.php create mode 100644 donnees/Database.php create mode 100644 modele/Livre.php create mode 100644 test.php diff --git a/controleur/LivreControleur.php b/controleur/LivreControleur.php new file mode 100644 index 0000000..6a3488b --- /dev/null +++ b/controleur/LivreControleur.php @@ -0,0 +1,24 @@ +livre = new Livre(); + } + + public function ajouterLivre() { + if (!empty($_POST['categorie']) && !empty($_POST['titre']) && !empty($_POST['auteur']) && !empty($_POST['annee'])) { + $this->livre->ajouter($_POST['categorie'], $_POST['titre'], $_POST['auteur'], $_POST['annee']); + } + } + + public function listerLivres() { + return $this->livre->getAll(); + } +} + + +?> \ No newline at end of file diff --git a/controleur/afficherLivres.php b/controleur/afficherLivres.php index ef22c8f..7c208e6 100644 --- a/controleur/afficherLivres.php +++ b/controleur/afficherLivres.php @@ -1,7 +1,7 @@ listerLivres(); include("../vue/header.php"); include("../vue/bibliotheque.php"); diff --git a/controleur/ajouterLivre.php b/controleur/ajouterLivre.php index 01b254e..379fbd0 100644 --- a/controleur/ajouterLivre.php +++ b/controleur/ajouterLivre.php @@ -1,8 +1,8 @@ ajouterLivre(); $categories = getCategories(); include("../vue/header.php"); diff --git a/controleur/classes/Database.php b/controleur/classes/Database.php deleted file mode 100644 index e69de29..0000000 diff --git a/controleur/classes/Livre.php b/controleur/classes/Livre.php deleted file mode 100644 index c1ca55f..0000000 --- a/controleur/classes/Livre.php +++ /dev/null @@ -1,14 +0,0 @@ - \ No newline at end of file diff --git a/controleur/classes/LivreControleur.php b/controleur/classes/LivreControleur.php deleted file mode 100644 index 15c5adc..0000000 --- a/controleur/classes/LivreControleur.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/donnees/Database.php b/donnees/Database.php new file mode 100644 index 0000000..8437d2a --- /dev/null +++ b/donnees/Database.php @@ -0,0 +1,20 @@ +ip;dbname=$this->database;charset=utf8mb4"; + try { + $db = new PDO($dsn, $this->user, $this->pass); + return $db; + } catch (PDOException $e) { + die("Erreur de connexion : " . $e->getMessage()); + } + } +} + +?> \ No newline at end of file diff --git a/modele/Livre.php b/modele/Livre.php new file mode 100644 index 0000000..c9bbfc7 --- /dev/null +++ b/modele/Livre.php @@ -0,0 +1,26 @@ +db = $database->connexionDB(); + } + + public function getAll() { + $stmt = $this->db->query("SELECT * FROM livres"); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } + + public function ajouter($categorie, $titre, $auteur, $annee) { + $stmt = $this->db->prepare("INSERT INTO livres (categorie, titre, auteur, annee) VALUES (?, ?, ?, ?)"); + $stmt->execute([$categorie, $titre, $auteur, $annee]); + } +} + +$livres = new Livre(); +var_dump($livres->getAll()); + +?> \ No newline at end of file diff --git a/modele/livres.php b/modele/livres.php index 6ec3f8a..bb2a6a3 100644 --- a/modele/livres.php +++ b/modele/livres.php @@ -1,5 +1,4 @@ getAll()); + +?> \ No newline at end of file