-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
34 lines (26 loc) · 699 Bytes
/
db.php
File metadata and controls
34 lines (26 loc) · 699 Bytes
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
<?php
class DB {
private $host = "localhost";
private $db_name = "erapid";
private $user = "root";
private $password = "";
public $conn;
protected static $con;
private function __construct() {
try {
self::$con = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->user, $this->password);
self::$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
self::$con->setAttribute( PDO::ATTR_PERSISTENT, false );
} catch (PDOException $e) {
echo 'Could not connect to database';
exit;
}
}
public static function getConnection() {
if(!self::$con) {
new DB();
}
return self::$con;
}
}
?>