-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
59 lines (49 loc) · 1.45 KB
/
config.php
File metadata and controls
59 lines (49 loc) · 1.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'project_management_system');
// define('DB_HOST', 'localhost');
// define('DB_USER', 'Vignesh_G');
// define('DB_PASS', 'Vigneshg091002');
// define('DB_NAME', 'PMS');
class Database {
private static $instance = null;
private $conn;
private function __construct() {
try {
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
$this->conn->set_charset("utf8mb4");
} catch (Exception $e) {
die("Database connection error: " . $e->getMessage());
}
}
public static function getInstance() {
if (self::$instance === null) {
self::$instance = new Database();
}
return self::$instance;
}
public function getConnection() {
return $this->conn;
}
public function query($sql) {
return $this->conn->query($sql);
}
public function prepare($sql) {
return $this->conn->prepare($sql);
}
public function escape($string) {
return $this->conn->real_escape_string($string);
}
public function lastInsertId() {
return $this->conn->insert_id;
}
}
function getDB() {
return Database::getInstance()->getConnection();
}
?>