1 |
commit: 1ce3c9c90a14683c6900e9812202c6fa355e53df |
2 |
Author: Brian Evans <grknight <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 30 15:38:23 2018 +0000 |
4 |
Commit: Brian Evans <grknight <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 30 15:38:23 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/bouncer.git/commit/?id=1ce3c9c9 |
7 |
|
8 |
Remove old db lib backup |
9 |
|
10 |
php/lib/db.php.orig | 306 ---------------------------------------------------- |
11 |
1 file changed, 306 deletions(-) |
12 |
|
13 |
diff --git a/php/lib/db.php.orig b/php/lib/db.php.orig |
14 |
deleted file mode 100644 |
15 |
index 23dd1ea..0000000 |
16 |
--- a/php/lib/db.php.orig |
17 |
+++ /dev/null |
18 |
@@ -1,306 +0,0 @@ |
19 |
-<?php |
20 |
-/** |
21 |
- * Minimal wrappers for core PHP mysql_* functions. |
22 |
- * @package mirror |
23 |
- * @subpackage lib |
24 |
- */ |
25 |
- |
26 |
-/** |
27 |
- * Connect to a MySQL database server. |
28 |
- * @param string $host db server, defaults to localhost |
29 |
- * @param string $user db username |
30 |
- * @param string $password db password |
31 |
- * @return resource dbh |
32 |
- */ |
33 |
-function db_connect($host='localhost',$user=null,$password=null) |
34 |
-{ |
35 |
- static $dbh = null; |
36 |
- if (!empty($host) && isset($user) && isset($password)) { |
37 |
- $dbh = @mysql_connect($host,$user,$password); |
38 |
- } |
39 |
- if (is_resource($dbh)) { |
40 |
- return $dbh; |
41 |
- } |
42 |
- else die("Unable to create database connection in db_connect()"); |
43 |
-} |
44 |
- |
45 |
-/** |
46 |
- * Select database. |
47 |
- * @param string $database name of the database to select |
48 |
- * @param resource $dbh valid dbh, null if not defined |
49 |
- * @return bool success of command |
50 |
- */ |
51 |
-function db_select($database,$dbh=null) |
52 |
-{ |
53 |
- if(is_resource($dbh)){ |
54 |
- return @mysql_select_db($database); |
55 |
- }else{ |
56 |
- return @mysql_select_db($database, db_connect()); |
57 |
- } |
58 |
- |
59 |
-} |
60 |
- |
61 |
-/** |
62 |
- * Execute a MySQL query. |
63 |
- * @param string $qry MySQL query |
64 |
- * @param resource $dbh valid dbh |
65 |
- */ |
66 |
-function db_query($qry=null,$dbh=null) |
67 |
-{ |
68 |
- static $result = null; |
69 |
- if(!is_resource($dbh)) $dbh = db_connect(); |
70 |
- printf("q:%s dbh=%s\n",$qry,$dbh); |
71 |
- if(is_null($qry)) |
72 |
- { |
73 |
- if(is_resource($result)) return $result; |
74 |
- else return false; |
75 |
- } |
76 |
- else |
77 |
- { |
78 |
- $result = mysql_query($qry,$dbh); |
79 |
- return $result; |
80 |
- } |
81 |
-} |
82 |
- |
83 |
-/** |
84 |
- * Fetch a row as an array from a result. |
85 |
- * @param string $result (default to null) |
86 |
- * @return array |
87 |
- */ |
88 |
-function db_fetch($result=null,$type=MYSQL_BOTH) |
89 |
-{ |
90 |
- if(!is_resource($result)) { |
91 |
- print 'Rerun query"'.$result.'"'; |
92 |
- return @mysql_fetch_array(db_query()); |
93 |
- } else { |
94 |
- return @mysql_fetch_array($result,$type); |
95 |
- } |
96 |
-} |
97 |
- |
98 |
-/** |
99 |
- * Fetch an array based on a query. |
100 |
- * @param string $query database query |
101 |
- * @param int $type result type |
102 |
- * @param string $col_id if passed it, the values of this column in the result set will be used as the array keys in the returned array |
103 |
- * @return array $list array of database rows |
104 |
- * Example of returned array: |
105 |
- * <code> |
106 |
- * db_get("SELECT * FROM table",MYSQL_ASSOC); |
107 |
- * returns... |
108 |
- * Array |
109 |
- * ( |
110 |
- * [0] => Array |
111 |
- * ( |
112 |
- * [id] => 1 |
113 |
- * [field1] => data1 |
114 |
- * [field2] => data2 |
115 |
- * ) |
116 |
- * |
117 |
- * ) |
118 |
- * </code> |
119 |
- */ |
120 |
-function db_get($query,$type=MYSQL_BOTH,$col_id=NULL) |
121 |
-{ |
122 |
- $res = db_query($query); |
123 |
- $list = array(); |
124 |
- if (is_resource($res) && !is_null($col_id) && ($type == MYSQL_BOTH || $type == MYSQL_ASSOC) && @mysql_num_rows($res) !== 0) { |
125 |
- $col_test = db_fetch($res,$type); |
126 |
- @mysql_data_seek($res, 0); |
127 |
- if (array_key_exists($col_id,$col_test)) { |
128 |
- while ( $buf = db_fetch($res,$type) ) { |
129 |
- $list[$buf[$col_id]] = $buf; |
130 |
- } |
131 |
- return $list; |
132 |
- } |
133 |
- } |
134 |
- while ( $buf = db_fetch($res,$type) ) { |
135 |
- $list[] = $buf; |
136 |
- } |
137 |
- return $list; |
138 |
-} |
139 |
- |
140 |
-/** |
141 |
- * Get all of the fieldnames for the specified table. |
142 |
- * @param string $table name of table to describe |
143 |
- * @return array array of column names, must be an array |
144 |
- */ |
145 |
-function db_fieldnames($table) |
146 |
-{ |
147 |
- $dbh = db_connect(); |
148 |
- $results = db_query("DESCRIBE $table"); |
149 |
- if (is_resource($results)) |
150 |
- { |
151 |
- while ($buf=db_fetch($results)) |
152 |
- { |
153 |
- $field_names[] = $buf[0]; |
154 |
- } |
155 |
- } |
156 |
- else |
157 |
- { |
158 |
- $field_names[] = 0; |
159 |
- } |
160 |
- return $field_names; |
161 |
-} |
162 |
- |
163 |
-/** |
164 |
- * Create a MySQL INSERT statement based on $_POST array generated by form submission. |
165 |
- * <ul> |
166 |
- * <li>does not work with mysql functions (PASSWORD, etc.) because there are forced double quotes</li> |
167 |
- * <li>do not use clean_in() before this, or you'll have double the slashes</li> |
168 |
- * <li>use the function only when it saves you time, not _always_</li> |
169 |
- * <li>form items not set will not be processed (unchecked radios, checkboxes) - handle these manually, or don't use the func</li> |
170 |
- * </ul> |
171 |
- * @param array $vars array of posts |
172 |
- * @param string $table name of the table that fields will be inserted into |
173 |
- * @return string $query resulting MySQL insert string |
174 |
- */ |
175 |
-function db_makeinsert($vars,$table) |
176 |
-{ |
177 |
- $dbh = db_connect(); |
178 |
- $fields = db_fieldnames($table); |
179 |
- foreach ($fields as $field) |
180 |
- { |
181 |
- if (get_magic_quotes_gpc) $vars[$field] = stripslashes($vars[$field]); |
182 |
- $vars[$field] = addslashes($vars[$field]); |
183 |
- if (isset($vars[$field])) |
184 |
- { |
185 |
- isset($q1)?$q1 .= ','.$field:$q1='INSERT INTO '.$table.'('.$field; |
186 |
- isset($q2)?$q2 .= ",'$vars[$field]'":$q2=" VALUES('$vars[$field]'"; |
187 |
- } |
188 |
- } |
189 |
- $q1 .= ')'; |
190 |
- $q2 .= ')'; |
191 |
- $query = $q1.$q2; |
192 |
- return $query; |
193 |
-} |
194 |
- |
195 |
-/** |
196 |
- * Create a MySQL REPLACE statement based on $_POST array generated by form submission. |
197 |
- * <ul> |
198 |
- * <li>does not work with mysql functions (PASSWORD, etc.) because there are forced double quotes</li> |
199 |
- * <li>do not use clean_in() before this, or you'll have double the slashes</li> |
200 |
- * <li>use the function only when it saves you time, not _always_</li> |
201 |
- * <li>form items not set will not be processed (unchecked radios, checkboxes) - handle these manually, or don't use the func</li> |
202 |
- * </ul> |
203 |
- * @param array $vars array of posts |
204 |
- * @param string $table name of the table that fields will be inserted into |
205 |
- * @return string $query resulting MySQL insert string |
206 |
- */ |
207 |
-function db_makereplace($vars,$table) |
208 |
-{ |
209 |
- $dbh = db_connect(); |
210 |
- $fields = db_fieldnames($table); |
211 |
- foreach ($fields as $field) |
212 |
- { |
213 |
- if (get_magic_quotes_gpc) $vars[$field] = stripslashes($vars[$field]); |
214 |
- $vars[$field] = addslashes($vars[$field]); |
215 |
- if (isset($vars[$field])) |
216 |
- { |
217 |
- isset($q1)?$q1 .= ','.$field:$q1='REPLACE INTO '.$table.'('.$field; |
218 |
- isset($q2)?$q2 .= ",'$vars[$field]'":$q2=" VALUES('$vars[$field]'"; |
219 |
- } |
220 |
- } |
221 |
- $q1 .= ')'; |
222 |
- $q2 .= ')'; |
223 |
- $query = $q1.$q2; |
224 |
- return $query; |
225 |
-} |
226 |
- |
227 |
-/** |
228 |
- * Create a MySQL UPDATE statement based on $_POST array generated by form submission. |
229 |
- * <ul> |
230 |
- * <li>does not work with mysql functions (PASSWORD, etc.) because there are forced double quotes</li> |
231 |
- * <li>do not use clean_in() before this, or you'll have double the slashes</li> |
232 |
- * <li>use the function only when it saves you time, not _always_</li> |
233 |
- * <li>form items not set will not be processed (unchecked radios, checkboxes) - handle these manually, or don't use the func</li> |
234 |
- * </ul> |
235 |
- * @param array $vars array of posts |
236 |
- * @param string $table name of the table that fields will be inserted into |
237 |
- * @param string $where where clause, describing which records are to be updated |
238 |
- */ |
239 |
-function db_makeupdate($vars,$table,$where) |
240 |
-{ |
241 |
- $dbh = db_connect(); |
242 |
- $fields = db_fieldnames($table); |
243 |
- foreach ($fields as $field) |
244 |
- { |
245 |
- if (isset($vars[$field])) |
246 |
- { |
247 |
- if (get_magic_quotes_gpc()) $vars[$field] = stripslashes($vars[$field]); |
248 |
- $vars[$field]=addslashes($vars[$field]); |
249 |
- $q1 = isset($q1)?$q1 .= ' ,'.$field."='$vars[$field]'":'UPDATE '.$table.' set '.$field."='$vars[$field]'"; |
250 |
- } |
251 |
- } |
252 |
- $query = $q1.' '.$where; |
253 |
- return $query; |
254 |
-} |
255 |
- |
256 |
-/** |
257 |
- * Since PHP's mysql_insert_id() sometimes throws an error, this is the replacement |
258 |
- * @param resource $dbh optional dbh to get the last inserted id from |
259 |
- * @return int the return value of MySQL's last_insert_id() |
260 |
- */ |
261 |
-function db_insert_id($dbh=null) |
262 |
-{ |
263 |
- if(!is_resource($dbh)) $dbh = db_connect(); |
264 |
- $buf = db_fetch(db_query("SELECT LAST_INSERT_ID()", $dbh)); |
265 |
- return empty($buf[0]) ? false : $buf[0]; |
266 |
-} |
267 |
- |
268 |
-/** |
269 |
- * Determine number of rows in result. |
270 |
- * @param resource $result mysql result |
271 |
- * @return int number of rows in query result |
272 |
- */ |
273 |
-function db_numrows($result=null) |
274 |
-{ |
275 |
- return (!is_resource($result))? @mysql_num_rows(db_query()) : @mysql_num_rows($result); |
276 |
-} |
277 |
- |
278 |
-/** |
279 |
- * Close the db connection. If a dbh is not specified, assume the last opened link. |
280 |
- * @param resource $dbh optional dbh to close |
281 |
- */ |
282 |
-function db_close($dbh=null) |
283 |
-{ |
284 |
- return is_resource($dbh)?@mysql_close($dbh):@mysql_close(); |
285 |
-} |
286 |
- |
287 |
-/** |
288 |
- * Get one record. |
289 |
- * @param string $query query |
290 |
- * @param int $type result type |
291 |
- */ |
292 |
-function db_get_one($query,$type=MYSQL_ASSOC) { |
293 |
- $buf = db_get($query.' LIMIT 1',$type); |
294 |
- return $buf[0]; |
295 |
-} |
296 |
- |
297 |
-/** |
298 |
- * Get an ID based on name. |
299 |
- * @param string $table |
300 |
- * @param string $id_col |
301 |
- * @param string $name_col |
302 |
- * @param string $name |
303 |
- */ |
304 |
-function db_name_to_id($table,$id_col,$name_col,$name) |
305 |
-{ |
306 |
- $q = "SELECT {$id_col} FROM {$table} WHERE {$name_col} = '{$name}'"; |
307 |
- print 'Query: '.$q."<br />\n"; |
308 |
- $buf = db_get_one($q, MYSQL_NUM); |
309 |
- return $buf[0]; |
310 |
-} |
311 |
- |
312 |
-/** |
313 |
- * Sets enum booleans to their opposite |
314 |
- * @param string $table |
315 |
- * @param string $pri |
316 |
- * @param string $col |
317 |
- * @param array $id |
318 |
- * @return int |
319 |
- */ |
320 |
-function db_toggle_bool($table, $pri, $col, $id) |
321 |
-{ |
322 |
- return db_query("UPDATE {$table} SET {$col} = IF({$col} = '1', '0', '1') WHERE {$pri} = {$id}"); |
323 |
-} |
324 |
-?> |