-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.php
47 lines (41 loc) · 1.15 KB
/
Database.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
<?php
require_once 'config.php';
class Database
{
private $username;
private $password;
private $host;
private $database;
public function __construct()
{
$this->username = USERNAME;
$this->password = PASSWORD;
$this->host = HOST;
$this->database = DATABASE;
}
public static function establishConnection() : PDO
{
$database = new self();
return $database->connect();
}
public function connect()
{
try {
$conn = new PDO(
"mysql:host=$this->host;dbname=$this->database;charset=utf8mb4",
$this->username,
$this->password,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => false,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4 COLLATE utf8mb4_general_ci"
)
);
//$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
catch(PDOException $e){
die("Connection failed ".$e->getMessage());
}
}
}