-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.class.php
84 lines (75 loc) · 1.85 KB
/
comment.class.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
74
75
76
77
78
79
80
81
82
83
84
<?php
class Comment
{
private $db;
function __construct($conn)
{
$this->db = $conn;
}
public function getIdComment($id_comment)
{
$this->id_comment = $id_comment;
return $this->id_comment;
}
public function getIdUser($id_user)
{
$this->id_user = $id_user;
return $this->id_user;
}
public function getComment($comment)
{
$this->comment = $comment;
return $this->comment;
}
public function getCreationDate($creation_date)
{
$this->creation_date = $creation_date;
return $this->creation_date;
}
public function addComment()
{
if(!empty($this->id_user) && !empty($this->comment) && !empty($this->creation_date))
{
$this->db->query( 'USE db_camagru' );
$requete = $this->db->prepare("INSERT INTO `Comments` (`id_user`, `comment`, `creation_date`)
VALUES(:id_user, :comment, :creation_date)");
$requete->bindparam(':id_user', $this->id_user);
$requete->bindparam(':comment', $this->comment);
$requete->bindparam(':creation_date', $this->creation_date);
$requete->execute();
}
else
{
echo "Error";
}
}
public function findIdComment()
{
if(!empty($this->id_user) && !empty($this->comment))
{
$id_user = $this->id_user;
$comment = $this->comment;
$this->db->query( 'USE db_camagru' );
$requete = $this->db->prepare("SELECT `id_comment` FROM `comments` WHERE `id_user` = :id_user AND `comment` = :comment");
$requete->bindparam(':id_user', $id_user);
$requete->bindparam(':comment', $comment);
$requete->execute();
$data = $requete->fetch(PDO::FETCH_ASSOC);
return $data['id_comment'];
}
else
{
return NULL;
echo "Error";
}
}
public function countNbCommentTotal()
{
$this->db->query( 'USE db_camagru' );
$requete = $this->db->prepare("SELECT count(`id_comment`) from `comments`");
$requete->execute();
$data = $requete->fetchColumn();
return $data;
}
}
?>