Files
D3-A01BibliMVC/modele/livres.php
2025-09-11 11:25:49 +02:00

20 lines
737 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
include("../donnees/connexion.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);
}
?>