|
71 | 71 | }
|
72 | 72 | $get['time'] = $timestamp;
|
73 | 73 |
|
74 |
| -class dbstuff { |
75 |
| - var $querynum = 0; |
76 |
| - var $link; |
77 |
| - var $histories; |
78 |
| - var $time; |
79 |
| - var $tablepre; |
80 |
| - |
81 |
| - function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset, $pconnect = 0, $tablepre='', $time = 0) { |
82 |
| - $this->time = $time; |
83 |
| - $this->tablepre = $tablepre; |
84 |
| - if($pconnect) { |
85 |
| - if(!$this->link = mysql_pconnect($dbhost, $dbuser, $dbpw)) { |
86 |
| - $this->halt('Can not connect to MySQL server'); |
87 |
| - } |
88 |
| - } else { |
89 |
| - if(!$this->link = mysql_connect($dbhost, $dbuser, $dbpw, 1)) { |
90 |
| - $this->halt('Can not connect to MySQL server'); |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - if($this->version() > '4.1') { |
95 |
| - if($dbcharset) { |
96 |
| - mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->link); |
97 |
| - } |
98 |
| - |
99 |
| - if($this->version() > '5.0.1') { |
100 |
| - mysql_query("SET sql_mode=''", $this->link); |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 |
| - if($dbname) { |
105 |
| - mysql_select_db($dbname, $this->link); |
106 |
| - } |
107 |
| - |
108 |
| - } |
109 |
| - |
110 |
| - function fetch_array($query, $result_type = MYSQL_ASSOC) { |
111 |
| - return mysql_fetch_array($query, $result_type); |
112 |
| - } |
113 |
| - |
114 |
| - function result_first($sql) { |
115 |
| - $query = $this->query($sql); |
116 |
| - return $this->result($query, 0); |
117 |
| - } |
118 |
| - |
119 |
| - function fetch_first($sql) { |
120 |
| - $query = $this->query($sql); |
121 |
| - return $this->fetch_array($query); |
122 |
| - } |
123 |
| - |
124 |
| - function fetch_all($sql) { |
125 |
| - $arr = array(); |
126 |
| - $query = $this->query($sql); |
127 |
| - while($data = $this->fetch_array($query)) { |
128 |
| - $arr[] = $data; |
129 |
| - } |
130 |
| - return $arr; |
131 |
| - } |
132 |
| - |
133 |
| - function cache_gc() { |
134 |
| - $this->query("DELETE FROM {$this->tablepre}sqlcaches WHERE expiry<$this->time"); |
135 |
| - } |
136 |
| - |
137 |
| - function query($sql, $type = '', $cachetime = FALSE) { |
138 |
| - $func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query'; |
139 |
| - if(!($query = $func($sql, $this->link)) && $type != 'SILENT') { |
140 |
| - $this->halt('MySQL Query Error', $sql); |
141 |
| - } |
142 |
| - $this->querynum++; |
143 |
| - $this->histories[] = $sql; |
144 |
| - return $query; |
145 |
| - } |
146 |
| - |
147 |
| - function affected_rows() { |
148 |
| - return mysql_affected_rows($this->link); |
149 |
| - } |
150 |
| - |
151 |
| - function error() { |
152 |
| - return (($this->link) ? mysql_error($this->link) : mysql_error()); |
153 |
| - } |
154 |
| - |
155 |
| - function errno() { |
156 |
| - return intval(($this->link) ? mysql_errno($this->link) : mysql_errno()); |
157 |
| - } |
158 |
| - |
159 |
| - function result($query, $row) { |
160 |
| - $query = @mysql_result($query, $row); |
161 |
| - return $query; |
162 |
| - } |
163 |
| - |
164 |
| - function num_rows($query) { |
165 |
| - $query = mysql_num_rows($query); |
166 |
| - return $query; |
167 |
| - } |
168 |
| - |
169 |
| - function num_fields($query) { |
170 |
| - return mysql_num_fields($query); |
171 |
| - } |
172 |
| - |
173 |
| - function free_result($query) { |
174 |
| - return mysql_free_result($query); |
175 |
| - } |
176 |
| - |
177 |
| - function insert_id() { |
178 |
| - return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0); |
179 |
| - } |
180 |
| - |
181 |
| - function fetch_row($query) { |
182 |
| - $query = mysql_fetch_row($query); |
183 |
| - return $query; |
184 |
| - } |
185 |
| - |
186 |
| - function fetch_fields($query) { |
187 |
| - return mysql_fetch_field($query); |
188 |
| - } |
189 |
| - |
190 |
| - function version() { |
191 |
| - return mysql_get_server_info($this->link); |
192 |
| - } |
193 |
| - |
194 |
| - function escape_string($str) { |
195 |
| - return mysql_escape_string($str); |
196 |
| - } |
197 |
| - |
198 |
| - function close() { |
199 |
| - return mysql_close($this->link); |
200 |
| - } |
201 |
| - |
202 |
| - function halt($message = '', $sql = '') { |
203 |
| - api_msg('run_sql_error', $message.'<br /><br />'.$sql.'<br /> '.mysql_error()); |
204 |
| - } |
205 |
| -} |
206 | 74 | class dbstuffi {
|
207 | 75 | var $querynum = 0;
|
208 | 76 | var $link;
|
@@ -333,7 +201,7 @@ function halt($message = '', $sql = '') {
|
333 | 201 | }
|
334 | 202 |
|
335 | 203 |
|
336 |
| -$db = function_exists("mysql_connect") ? new dbstuff() : new dbstuffi(); |
| 204 | +$db = new dbstuffi(); |
337 | 205 | $version = '';
|
338 | 206 | if($apptype == 'discuz') {
|
339 | 207 |
|
|
0 commit comments