-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
api.dbconnect.php
130 lines (109 loc) · 3.4 KB
/
api.dbconnect.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
error_reporting(E_ALL ^ E_DEPRECATED); //hide some deprecated warnings on 5.6 :(
class DbConnect {
var $host = '';
var $user = '';
var $password = '';
var $database = '';
var $persistent = false;
var $conn = NULL;
var $result = false;
var $error_reporting = false;
public function __construct($host, $user, $password, $database, $error_reporting = true, $persistent = false) {
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->persistent = $persistent;
$this->error_reporting = $error_reporting;
}
public function open() {
if (!extension_loaded('mysqli')) {
if ($this->persistent) {
$func = 'mysql_pconnect';
} else {
$func = 'mysql_connect';
}
$this->conn = $func($this->host, $this->user, $this->password);
if (!$this->conn) {
return false;
}
if (@!mysql_select_db($this->database, $this->conn)) {
return false;
}
} else {
$this->conn = new mysqli($this->host, $this->user, $this->password, $this->database);
if ($this->conn->connect_error) {
return false;
}
}
return true;
}
public function close() {
if (!extension_loaded('mysqli')) {
return (@mysql_close($this->conn));
} else {
return (@$this->conn->close());
}
}
public function error() {
if ($this->error_reporting) {
if (!extension_loaded('mysqli')) {
return (mysql_error());
} else {
return ($this->conn->connect_error);
}
}
}
public function query($sql) {
if (!extension_loaded('mysqli')) {
$this->result = @mysql_query($sql, $this->conn);
} else {
$this->result = @$this->conn->query($sql);
}
return($this->result != false);
}
public function affectedrows() {
if (!extension_loaded('mysqli')) {
return(@mysql_affected_rows($this->conn));
} else {
return(@$this->conn->affected_rows);
}
}
public function numrows() {
if (!extension_loaded('mysqli')) {
return(@mysql_num_rows($this->result));
} else {
return(@$this->conn->num_rows);
}
}
public function fetchobject() {
if (!extension_loaded('mysqli')) {
return(@mysql_fetch_object($this->result, MYSQL_ASSOC));
} else {
return($result = $this->result->fetch_object());
}
}
public function fetcharray() {
if (!extension_loaded('mysqli')) {
return(mysql_fetch_array($this->result));
} else {
return($result = @$this->result->fetch_array(MYSQLI_NUM));
}
}
public function fetchassoc() {
if (!extension_loaded('mysqli')) {
return(@mysql_fetch_assoc($this->result));
} else {
return($result = @$this->result->fetch_assoc());
}
}
public function freeresult() {
if (!extension_loaded('mysqli')) {
return(@mysql_free_result($this->result));
} else {
return(@$this->result->free());
}
}
}
?>