-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
83 lines (68 loc) · 1.86 KB
/
config.php
File metadata and controls
83 lines (68 loc) · 1.86 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Created by PhpStorm.
* User: Gavin
* Date: 2/25/16
* Time: 8:25 PM
*/
class Database
{
// Store the single instance of Database
private static $m_pInstance;
private $db_host='localhost:33333';
private $db_user = 'gavin';
private $db_pass = 'password';
private $db_name = 'gatorloop';
private static $conn;
// Private constructor to limit object instantiation to within the class
private function __construct()
{
self::$conn = new mysqli($this->db_host,$this->db_user,$this->db_pass);
mysqli_select_db(self::$conn, $this->db_name);
}
// Getter method for creating/returning the single instance of this class
public static function getInstance()
{
if (!self::$m_pInstance)
{
self::$m_pInstance = new Database();
}
return self::$m_pInstance;
}
public function query($query)
{
$stmt = self::$conn->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function query_with_params($query, $params) {
$stmt = self::$conn->prepare($query);
if($stmt) {
call_user_func_array(array($stmt, 'bind_param'), self::refValues($params));
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
else {
print("prepare failed");
print($query);
return 0;
}
}
private function refValues($arr){
if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
{
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
return $arr;
}
public function __destruct()
{
self::$conn->close();
}
}
?>