Branche classes

This commit is contained in:
2025-09-14 22:19:37 +02:00
parent 2a1804109b
commit 1aafd18ccd
10 changed files with 80 additions and 22 deletions

26
modele/Livre.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
require("../donnees/Database.php");
class Livre {
private $db;
public function __construct() {
$database = new Database();
$this->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());
?>