-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySqlHelper.php
97 lines (80 loc) · 2.24 KB
/
MySqlHelper.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
class MySqlHelper
{
private $isProd = false;
private $connect_UserName = "silversi_janine";
private $connect_Password = "wynand1992";
private $connect_Server = "localhost";
private $connect_DB = "silversi_janine";
private $connection;
public function Connect()
{
$server = $this->connect_Server;
$userName = $this->connect_UserName;
$password = $this->connect_Password;
$db = $this->connect_DB;
$this->connection = mysqli_connect("$server", "$userName", "$password");
if (!$this->connection) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
mysqli_select_db($this->connection, "$db");
}
public function SafeValue($value)
{
return mysqli_real_escape_string($this->connection, stripslashes(ltrim(rtrim($value))));
}
public function Disconnect()
{
mysqli_close($this->connection);
}
public function GetLatestId()
{
return mysqli_insert_id($this->connection);
}
public function Query($string_query)
{
$res = mysqli_query($this->connection, $string_query);
if (!$res) {
echo mysqli_error($this->connection);
}
return $res;
}
public function GetRow($string_query)
{
$res = mysqli_query($this->connection, $string_query);
if (!$res) {
echo mysqli_error($this->connection);
}
return mysqli_fetch_assoc($res);
}
public function GetRows($string_query)
{
$query = mysqli_query($this->connection, $string_query);
$result = [];
if (!$query) {
echo mysqli_error($this->connection);
} else {
while ($row = mysqli_fetch_assoc($query)) {
$result[] = $row;
}
}
return $result;
}
public function AsBool($value)
{
return $value == "1";
}
public function AsInt($value)
{
return intval($value);
}
public function Now()
{
return date("Y-m-d H:i:s");
}
}
?>
<?php ?>