Update
This commit is contained in:
@@ -17,4 +17,5 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
13
test.php
13
test.php
@@ -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());
|
||||
|
||||
?>
|
Reference in New Issue
Block a user