-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.php
42 lines (37 loc) · 988 Bytes
/
model.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
<?php
/*
* Model
*/
//Fonction de recuperation des posts
function getPosts()
{
$bdd = dbConnect();
$Posts = $bdd->query("SELECT * FROM poster");
return $Posts;
}
//Fonction de recuperation d'un post en passant son id
function getPost($idPost)
{
$bdd = dbConnect();
$Post = $bdd->prepare("SELECT pseudo, message FROM poster WHERE Id = :identifiant");
$Post->exec(array("identifiant"=>$idPost));
return $Post;
}
//Fonction de recuperation des commentaires en passant l'id du poste
function getComments($idPost)
{
$bdd = dbConnect();
$Comments = $bdd->prepare("SELECT commentaire, id_post FROM post_commente WHERE id_post = :identifiant");
$Comments->exec(array('identifiant'=>$idPost));
return $Comments;
}
//Fonction de connection à la base de donnée
function dbConnect()
{
try {
$bdd = new PDO("mysql:host=localhost;dbname=posts",'root','');
return $bdd;
} catch (Exception $e) {
die("Erreur :".$e->getMessage());
}
}