-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.php
86 lines (60 loc) · 2.15 KB
/
conn.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
85
86
<?php
//connection to database
try {
$pdo = new PDO('mysql:host=localhost;dbname=mliminet'," "," ");
} catch (PDOException $th) {
include 'menubar.php';
echo '<center> <h4 class="text-warning">Unable to connect to database server</h4></center>';
exit();
}
class Data{
public function fetch(){
global $pdo;
$query=$pdo->prepare("SELECT * FROM homearticles,advisor WHERE advisor.id_advisor = homearticles.id_advisor ORDER BY time ASC");
$query->execute();
return $query->fetchAll();
}
// public function Author(){
// global $pdo;
// $query=$pdo->prepare("SELECT * FROM advisor , homearticles WHERE advisor.id_advisor = homearticles.id_advisor");
// $query->execute();
// return $query->fetchAll();
// }
public function fetchFarmer($email,$password){
global $pdo;
$query=$pdo->prepare("SELECT * FROM farmer WHERE farmer_email=? AND password_farmer=?");
$query->bindValue(1,$email);
$query->bindValue(2,$password);
$query->execute();
return $query->fetch();
}
public function FarmerProfile($id){
global $pdo;
$query=$pdo->prepare("SELECT * FROM farmer WHERE id_farmer=?");
$query->bindValue(1,$id);
$query->execute();
return $query->fetch();
}
public function fetchData($id){
global $pdo;
$query=$pdo->prepare("SELECT * FROM homearticles WHERE id=?");
$query->bindValue(1,$id);
$query->execute();
return $query->fetch ();
}
public function fetchComments($id){
global $pdo;
$query=$pdo->prepare("SELECT * FROM postcomments WHERE id=? ORDER BY time DESC");
$query->bindValue(1,$id);
$query->execute();
return $query->fetchAll();
}
public function numComments($id){
global $pdo;
$query=$pdo->prepare("SELECT count(*) AS 'number' FROM postcomments WHERE id=? ORDER BY time DESC");
$query->bindValue(1,$id);
$query->execute();
return $query->fetch();
}
}
?>