26 lines
652 B
PHP
26 lines
652 B
PHP
<?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());
|
|
|
|
?>
|