-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.php
More file actions
37 lines (26 loc) · 766 Bytes
/
connection.php
File metadata and controls
37 lines (26 loc) · 766 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
35
36
37
<!-- Database Connection using Singleton pattern -->
<?php
class DBConnection {
private $servername = "mysql";
private $username = "developer";
private $password = "safepass";
private $dbname = "login";
private $connection;
static $db_connection = null;
private function __construct() {
$this->connection = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
if ($this->connection->connect_error) {
die("Connection failed: " . $this->connection->connect_error);
}
}
public static function get_instance () {
if (is_null(self::$db_connection)) {
self::$db_connection = new DBConnection();
}
return self::$db_connection;
}
public function get_connection () {
return $this->connection;
}
}
?>