/
Categorie.php
73 lines (57 loc) · 1.35 KB
/
Categorie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class Categorie {
private $bdd;
private $id;
private $titre;
private $accroche;
private $categorieExiste;
function __construct ($id, $bdd){
//include('connectionbdd.php');
$this->bdd = $bdd;
$this->id = $id;
$this->categorieExiste = $this->existeId();
if ($this->categorieExiste){
$this->recupereDonnees();
}
}
// Fonctions necessaires au bon fonctionnement
public function recupereDonnees (){
$req = $this->bdd->prepare('SELECT titre,accroche FROM `Categorie` WHERE id = ?');
$req->execute(array($this->id));
$donnees = $req->fetch();
$req->closeCursor();
$this->titre = $donnees['titre'];
$this->accroche = $donnees['accroche'];
}
function existeId(){
$bdd = $this->bdd ;
// recuperation du est ce que la personne existe selon un id
$req = $bdd->prepare('SELECT COUNT(id) FROM `Categorie` WHERE id = ?');
$req->execute(array($this->id));
$donnees = $req->fetch();
$req->closeCursor(); // Important : on libère le curseur pour la prochaine requête
if ($donnees[0] == 0){
return false;
}
return true ;
}
// Getter
/*
getId
getTitre
getCorps
*/
public function getId(){
return $this->id;
}
public function getTitre(){
return $this->titre;
}
public function getCorps(){
return $this->corps;
}
public function getCategorieExiste(){
return $this->categorieExiste;
}
}
?>