-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.php
54 lines (47 loc) · 1.28 KB
/
repository.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
<?php
class Repository
{
private $db = null;
public function __construct()
{
$this->db = new PDO(
'mysql:host=' . getenv('DbUrl') . ';dbname=' . getenv('DbName') . ';charset=utf8mb4',
getenv('DbUser'),
getenv('DbPassword'),
array(
PDO::MYSQL_ATTR_SSL_CA => '/path/to/ssl-cert.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
)
);
$this->db->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
);
}
public function getReceivers() {
$stmt = $this->db->prepare('
SELECT *
FROM receiver
ORDER BY name
');
$stmt->execute();
return $stmt->fetchAll();
}
public function getLoves($id) {
$stmt = $this->db->prepare('
SELECT *
FROM love
WHERE id_receiver = ?
');
$stmt->execute([$id]);
return $stmt->fetchAll();
}
public function insertLove($to, $from, $message) {
$stmt = $this->db->prepare('
INSERT INTO love (id_receiver, sender, content)
VALUES (?, ?, ?)
');
$stmt->execute([$to, $from, $message]);
}
}
?>