-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBHandler.php
63 lines (57 loc) · 1.81 KB
/
DBHandler.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
<?php
class DBHandler
{
private $db;
function __construct()
{
$this->connect_database();
}
public function getInstance()
{
return $this->db;
}
public function getDb()
{
if ($this->db instanceof PDO) {
return $this->db;
}
}
private function connect_database()
{
if (isset($_SESSION['Category'])) {
switch ($_SESSION['Category']) {
case "User":
define('USER', 'user');
define('PASSWORD', 'UqZ)SA5/C?buu.6^"9t!!>!^kh"=?+vP');
break;
case "Chef":
define('USER', 'chef');
define('PASSWORD', 'A.Djh!]XQg<TrTX+Gx(&V@fPv74qnTL~');
break;
case "Administrator":
define('USER', 'admin');
define('PASSWORD', ';E&w#!%Br]]XtJLSe@$XY}qD<r3g2u2n');
break;
default:
define('USER', 'nouser');
define('PASSWORD', '4KsKhh{PL>4Mhcw7v;FE)~,6r6!Yzf!L');
break;
}
} else {
define('USER', 'nouser');
define('PASSWORD', '4KsKhh{PL>4Mhcw7v;FE)~,6r6!Yzf!L');
}
// Database connection
try {
$connection_string = 'mysql:host=localhost;dbname=foodblog;charset=utf8';
$connection_array = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$this->db = new PDO($connection_string, USER, PASSWORD, $connection_array);
// echo 'Database connection established';
} catch (PDOException $e) {
$this->db = null;
}
}
}