Files
D3-A01BibliMVC/modele/livres.php
2025-09-14 22:19:37 +02:00

19 lines
700 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Ajout dun livre
function addLivre() {
include("../donnees/connexion.php");
if (!empty($_POST['categorie']) && !empty($_POST['titre']) && !empty($_POST['auteur']) && !empty($_POST['annee'])) {
$stmt = $db->prepare("INSERT INTO livres (categorie, titre, auteur, annee) VALUES (?, ?, ?, ?)");
$stmt->execute([$_POST['categorie'], $_POST['titre'], $_POST['auteur'], $_POST['annee']]);
}
}
// Récupération des livres
function getLivres() {
include("../donnees/connexion.php");
$stmt = $db->query("SELECT livres.*, categories.nom FROM livres INNER JOIN categories ON categories.id = livres.categorie");
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>