-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseConnection.php
More file actions
38 lines (31 loc) · 1.13 KB
/
DatabaseConnection.php
File metadata and controls
38 lines (31 loc) · 1.13 KB
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
<?php
/** Singleton Design Pattern */
final class DatabaseConnection {
private static $instance = null;
private $databaseConnection = null;
private $databaseHost = "localhost";
private $databaseUser = "root";
private $databasePassword = "";
private $database = "testing_ground";
private $databasePort = 3306;
#private $databaseSocket = null;
private function __construct() {
$this->databaseConnection = mysqli_connect($this->databaseHost, $this->databaseUser, $this->databasePassword, $this->database, $this->databasePort);
if (mysqli_connect_error()) {
trigger_error("Failed to conencto to MySQL: " . mysqli_connect_error(), E_USER_ERROR);
}
}
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new DatabaseConnection();
} else {
return self::$instance;
}
}
public function getConnection() {
return $this->connection;
}
}
//$db_connect=DatabaseConnection::getInstance();
//$myConnection = $db_connect->getConnection();
//$result = $myConnection->query($sql_query);