forked from AustinWise/fleet_links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataManager.php
More file actions
62 lines (51 loc) · 1.28 KB
/
Copy pathDataManager.php
File metadata and controls
62 lines (51 loc) · 1.28 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
60
61
62
<?php
require_once ("config.php");
class DataManager {
private static $instance = null;
public static function GetInstance() {
if (self::$instance == null) {
self::$instance = new DataManager();
}
return self::$instance;
}
private $conn;
private function __construct() {
global $cfg;
$server = $cfg['db']['server'];
$username = $cfg['db']['username'];
$password = $cfg['db']['password'];
$database = $cfg['db']['database'];
$this->conn = new mysqli($server, $username, $password, $database);
if ($this->conn->connect_error)
throw new Exception('Failed to connect to the database.');
}
public function CloseConnection() {
if (isset($this->conn)) {
$this->conn->close();
}
}
public function GetConnection() {
return $this->conn;
}
public function Query($query) {
return $this->conn->query($query);
}
public function QueryAndFetch($query) {
$result = $this->Query($query);
if ($result) {
$assoc = $result->fetch_assoc();
$result->close();
return $assoc;
}
else {
throw new Exception('Failed to execute query.');
}
}
public function EscapeString($str) {
return $this->conn->real_escape_string($str);
}
public function FormatTimestampForSql($time) {
return date('Y-m-d H:i:s', $time);
}
}
?>