-
Notifications
You must be signed in to change notification settings - Fork 1
/
Database.php
87 lines (73 loc) · 1.87 KB
/
Database.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
<?php
class MySQL{
/* Variables de BDD */
private $dbname = "@dbname";
private $dbuser = "@dbuser";
private $dbpssw = "@dbpassword";
private $dbsrvr = "@dbserver";
/* Variables de buffer */
private $resultSet;
private $query;
private $connection;
/* Variables de utilería */
private $wc = '/1QQ/';
public function MySQL(){
$this->connection =
mysqli_connect($this->dbsrvr,$this->dbuser,$this->dbpssw,$this->dbname);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
}
public function query($q = "eempty"){
if($q == "eempty")
$q = $this->query;
$this->resultSet = mysqli_query($this->connection,$q);
}
public function fetch($rS = "eempty"){
if($rS == "eempty")
$rS = $this->resultSet;
if(!$this->resultSet)
{
echo("Error description: " . mysqli_error($this->connection));
exit();
}
return mysqli_fetch_array($rS);
}
public function qarray($q = "eempty", $arr = array()){
$this->squery($q,$arr);
return $this->fetch();
}
public function qvalue($q = "eempty", $arr = array()){
return $this->qarray($q,$arr)[0];
}
public function rows($rS = "eempty"){
if($rS == "eempty")
$rS = $this->resultSet;
return mysqli_num_rows($rS);
}
public function secure($str){
$str = preg_replace('/</',"<",$str);
$str = preg_replace('/>/',">",$str);
return mysqli_real_escape_string($this->connection,$str);
}
public function secure_string($str,$arr){
foreach($arr as $a){
$aa = $this->secure($a);
$str = preg_replace($this->wc,$aa,$str,1);
}
return $str;
}
public function squery_rows($q = "eempty", $arr = array()){
$this->squery($q, $arr);
return $this->resultSet;
}
public function squery($q = "eempty", $arr = array()){
if(count($arr) == 0)
$this->query($q);
else
$this->query($this->secure_string($q,$arr));
}
}
?>