-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBC.php
46 lines (40 loc) · 1.24 KB
/
DBC.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
<?php
class DBC
{
private static $CREDENTIALS = null;
public static $SERVER_IP = null;
public static $USER = null;
public static $PASSWORD = null;
public static $DATABASE = null;
private static $connection = null;
protected function __construct()
{
}
public static function getConnection()
{
error_reporting(E_ALL);
ini_set('display_errors', 'on');
if (!self::$CREDENTIALS)
{
self::$CREDENTIALS = get_object_vars(json_decode(file_get_contents("sql_credentials.json")));
self::$SERVER_IP = self::$CREDENTIALS["ip"];
self::$USER = self::$CREDENTIALS["user"];
self::$PASSWORD = self::$CREDENTIALS["password"];
self::$DATABASE = self::$CREDENTIALS["database"];
}
if (!self::$connection) {
self::$connection = mysqli_connect(self::$SERVER_IP, self::$USER, self::$PASSWORD, self::$DATABASE);
if (!self::$connection) {
die('Could not connect to DB');
}
}
return self::$connection;
}
public static function closeConnection()
{
if (self::$connection) {
mysqli_close(self::$connection);
self::$connection = null;
}
}
}