-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.php
40 lines (33 loc) · 1.11 KB
/
connection.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
<?php
class Db {
protected static $dbHost = '';
protected static $dbScheme = '';
protected static $dbUser = '';
protected static $dbPass = '';
private static $instance = NULL;
private function __construct() {
$this->getInstance();
}
private static function getCredentials() {
$config = json_decode(json_encode(parse_ini_file("config.ini",true)));
self::$dbHost = $config->database->host;
self::$dbScheme = $config->database->schema;
self::$dbUser = $config->database->user;
self::$dbPass = $config->database->password;
}
private function __clone() {}
public static function getInstance() {
self::getCredentials();
if (!isset(self::$instance)) {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
try {
self::$instance = new PDO('mysql:host='.self::$dbHost.';dbname='.self::$dbScheme,self::$dbUser,self::$dbPass, $pdo_options);
} catch (Exception $e) {
print "something went wrong\n<pre>";
print_r($e) . '</pre>';
}
}
return self::$instance;
}
}
?>