First commit
This commit is contained in:
57
bibliotheque.php
Normal file
57
bibliotheque.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$ip = 'localhost';
|
||||||
|
$user = 'adminBibli';
|
||||||
|
$pass = 'mdpBibli';
|
||||||
|
$database = 'bdbibliotheque';
|
||||||
|
// Définition de la source des données pour PDO
|
||||||
|
|
||||||
|
$dsn = "mysql:host=$ip;dbname=$database;charset=utf8mb4";
|
||||||
|
|
||||||
|
// Création de l'objet $dbh, de type PDO, qui est la ressource d'accès à la base
|
||||||
|
try {
|
||||||
|
|
||||||
|
$db = new PDO($dsn, $user, $pass);
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
|
||||||
|
die("Erreur de connexion : ".$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajout d’un livre
|
||||||
|
if (!empty($_POST['titre']) && !empty($_POST['auteur']) && !empty($_POST['annee'])) {
|
||||||
|
$stmt = $db->prepare("INSERT INTO livres (titre, auteur, annee) VALUES (?, ?, ?)");
|
||||||
|
$stmt->execute([$_POST['titre'], $_POST['auteur'], $_POST['annee']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupération des livres
|
||||||
|
$stmt = $db->query("SELECT * FROM livres");
|
||||||
|
$livres = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Bibliothèque</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Gestion de la bibliothèque</h1>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<label>Titre : <input type="text" name="titre"></label><br>
|
||||||
|
<label>Auteur : <input type="text" name="auteur"></label><br>
|
||||||
|
<label>Année : <input type="number" name="annee"></label><br>
|
||||||
|
<button type="submit">Ajouter</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Liste des livres</h2>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($livres as $livre): ?>
|
||||||
|
<li><?= $livre['titre'] ?> - <?= $livre['auteur'] ?> (<?= $livre['annee'] ?>)</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
45
bibliotheque.sql
Normal file
45
bibliotheque.sql
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
DROP DATABASE IF EXISTS bdbibliotheque;
|
||||||
|
|
||||||
|
-- Base de données pour l'application Bibliothèque
|
||||||
|
CREATE DATABASE IF NOT EXISTS bdbibliotheque
|
||||||
|
DEFAULT CHARACTER SET utf8mb4
|
||||||
|
COLLATE utf8mb4_general_ci;
|
||||||
|
|
||||||
|
USE bdbibliotheque;
|
||||||
|
|
||||||
|
-- Table des catégories de livres
|
||||||
|
CREATE TABLE IF NOT EXISTS categories (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
nom VARCHAR(100)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Table des livres
|
||||||
|
CREATE TABLE IF NOT EXISTS livres (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
categorie INT NOT NULL,
|
||||||
|
titre VARCHAR(100) NOT NULL,
|
||||||
|
auteur VARCHAR(100) NOT NULL,
|
||||||
|
annee INT NOT NULL,
|
||||||
|
CONSTRAINT fk_livre_categorie
|
||||||
|
FOREIGN KEY (categorie)
|
||||||
|
REFERENCES categories (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Données de test
|
||||||
|
INSERT INTO categories (nom) VALUES
|
||||||
|
('Roman'),
|
||||||
|
('Manga'),
|
||||||
|
('Bande dessinée');
|
||||||
|
|
||||||
|
INSERT INTO livres (categorie, titre, auteur, annee) VALUES
|
||||||
|
(1, '1984', 'George Orwell', 1949),
|
||||||
|
(1, 'Le Petit Prince', 'Antoine de Saint-Exupéry', 1943),
|
||||||
|
(1, 'L’Étranger', 'Albert Camus', 1942),
|
||||||
|
(2, 'One Piece', 'Eiichirō Oda', 1997),
|
||||||
|
(2, 'Naruto', 'Masashi Kishimoto', 1999),
|
||||||
|
(2, 'Sun Ken Rock', 'Boichi', 2006),
|
||||||
|
(3, 'Astérix', 'René Goscinny', 1959);
|
||||||
|
|
||||||
|
-- Compte utilisateur administrateur pour accès distant à la base de données
|
||||||
|
CREATE USER 'adminBibli'@'%' IDENTIFIED BY 'mdpBibli';
|
||||||
|
GRANT ALL PRIVILEGES ON bdbibliotheque.* to "adminBibli"@"%";
|
9
controleur/afficherLivres.php
Normal file
9
controleur/afficherLivres.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
require("../modele/livres.php");
|
||||||
|
|
||||||
|
$livres = getLivres();
|
||||||
|
|
||||||
|
include("../vue/header.php");
|
||||||
|
include("../vue/bibliotheque.php");
|
||||||
|
include("../vue/footer.php");
|
||||||
|
?>
|
9
controleur/ajouterCategorie.php
Normal file
9
controleur/ajouterCategorie.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
require("../modele/categories.php");
|
||||||
|
|
||||||
|
addCategorie();
|
||||||
|
|
||||||
|
include("../vue/header.php");
|
||||||
|
include("../vue/gestion_categories.php");
|
||||||
|
include("../vue/footer.php");
|
||||||
|
?>
|
11
controleur/ajouterLivre.php
Normal file
11
controleur/ajouterLivre.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
require("../modele/livres.php");
|
||||||
|
require("../modele/categories.php");
|
||||||
|
|
||||||
|
addLivre();
|
||||||
|
$categories = getCategories();
|
||||||
|
|
||||||
|
include("../vue/header.php");
|
||||||
|
include("../vue/gestion_livres.php");
|
||||||
|
include("../vue/footer.php");
|
||||||
|
?>
|
0
controleur/classes/Database.php
Normal file
0
controleur/classes/Database.php
Normal file
14
controleur/classes/Livre.php
Normal file
14
controleur/classes/Livre.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Livre {
|
||||||
|
function getAll() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function ajouter($titre, $auteur, $annee) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
3
controleur/classes/LivreControleur.php
Normal file
3
controleur/classes/LivreControleur.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
7
controleur/pageAccueil.php
Normal file
7
controleur/pageAccueil.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include('./vue/header.php');
|
||||||
|
include('./vue/navigation.php');
|
||||||
|
include('./vue/footer.php');
|
||||||
|
|
||||||
|
?>
|
21
donnees/connexion.php
Normal file
21
donnees/connexion.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$ip = 'localhost';
|
||||||
|
$user = 'adminBibli';
|
||||||
|
$pass = 'mdpBibli';
|
||||||
|
$database = 'bdbibliotheque';
|
||||||
|
// Définition de la source des données pour PDO
|
||||||
|
|
||||||
|
$dsn = "mysql:host=$ip;dbname=$database;charset=utf8mb4";
|
||||||
|
|
||||||
|
// Création de l'objet $dbh, de type PDO, qui est la ressource d'accès à la base
|
||||||
|
try {
|
||||||
|
|
||||||
|
$db = new PDO($dsn, $user, $pass);
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
|
||||||
|
die("Erreur de connexion : ".$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
19
modele/categories.php
Normal file
19
modele/categories.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Récupération des catégories
|
||||||
|
function getCategories() {
|
||||||
|
include("../donnees/connexion.php");
|
||||||
|
$stmt = $db->query("SELECT * FROM categories");
|
||||||
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajout d'une catégorie
|
||||||
|
function addCategorie() {
|
||||||
|
include("../donnees/connexion.php");
|
||||||
|
if (!empty($_POST['nom'])) {
|
||||||
|
$stmt = $db->prepare("INSERT INTO categories (nom) VALUES (?)");
|
||||||
|
$stmt->execute([$_POST['nom']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
20
modele/livres.php
Normal file
20
modele/livres.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
include("../donnees/connexion.php");
|
||||||
|
|
||||||
|
// Ajout d’un 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
6
vue/bibliotheque.php
Normal file
6
vue/bibliotheque.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h2>Liste des livres</h2>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($livres as $livre): ?>
|
||||||
|
<li>[<?= $livre['nom'] ?>] <?= $livre['titre'] ?> - <?= $livre['auteur'] ?> (<?= $livre['annee'] ?>)</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
2
vue/footer.php
Normal file
2
vue/footer.php
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
</body>
|
||||||
|
</html>
|
6
vue/gestion_categories.php
Normal file
6
vue/gestion_categories.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1>Gestion des catégories</h1>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<label>Nom : <input type="text" name="nom"></label><br>
|
||||||
|
<button type="submit">Ajouter</button>
|
||||||
|
</form>
|
14
vue/gestion_livres.php
Normal file
14
vue/gestion_livres.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<h1>Gestion de la bibliothèque</h1>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<label>Catégorie :</label>
|
||||||
|
<select name="categorie">
|
||||||
|
<?php foreach ($categories as $categorie): ?>
|
||||||
|
<option value="<?= $categorie['id'] ?>"><?= $categorie['nom'] ?></option>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</select><br>
|
||||||
|
<label>Titre : <input type="text" name="titre"></label><br>
|
||||||
|
<label>Auteur : <input type="text" name="auteur"></label><br>
|
||||||
|
<label>Année : <input type="number" name="annee"></label><br>
|
||||||
|
<button type="submit">Ajouter</button>
|
||||||
|
</form>
|
8
vue/header.php
Normal file
8
vue/header.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Bibliothèque</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h4><a href="../index.php">Accueil</a></h4>
|
4
vue/navigation.php
Normal file
4
vue/navigation.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
<h1><a href="./controleur/afficherLivres.php">Liste des livres</a></h1>
|
||||||
|
<h1><a href="./controleur/ajouterLivre.php">Gestion des livres</a></h1>
|
||||||
|
<h1><a href="./controleur/ajouterCategorie.php">Gestion des catégories</a></h1>
|
Reference in New Issue
Block a user