This commit is contained in:
2025-09-15 16:09:07 +02:00
parent 1aafd18ccd
commit 3488cb8265
3 changed files with 21 additions and 13 deletions

View File

@@ -17,4 +17,5 @@ class Database {
}
}
?>

View File

@@ -1,21 +1,19 @@
<?php
require("../donnees/Database.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");
public static function getAll() {
require("donnees/Database.php");
$db = new Database()->connexionDB();
$stmt = $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 (?, ?, ?, ?)");
public static function ajouter($categorie, $titre, $auteur, $annee) {
require("donnees/Database.php");
$db = new Database()->connexionDB();
$stmt = $db->prepare("INSERT INTO livres (categorie, titre, auteur, annee) VALUES (?, ?, ?, ?)");
$stmt->execute([$categorie, $titre, $auteur, $annee]);
}
}

View File

@@ -1,6 +1,15 @@
<?php
require("./modele/Livre.php");
$livres = new Livre();
var_dump($livres->getAll());
$livre = new Livre();
echo $livre->test;
// require("./donnees/Database.php");
// var_dump(new Database()->connexionDB());
// $livres = new Livre();
// var_dump($livres->getAll());
?>