1
|
|
|
<?php |
2
|
|
|
namespace { |
3
|
|
|
|
4
|
|
|
if (!function_exists('\mysql_connect')) { |
5
|
|
|
define('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS); |
6
|
|
|
define('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE); |
7
|
|
|
define('MYSQL_CLIENT_INTERACTIVE', MYSQLI_CLIENT_INTERACTIVE); |
8
|
|
|
define('MYSQL_CLIENT_SSL', MYSQLI_CLIENT_SSL); |
9
|
|
|
|
10
|
|
|
function mysql_connect( |
11
|
|
|
$hostname = null, |
12
|
|
|
$username = null, |
13
|
|
|
$password = null, |
14
|
|
|
$new = false, |
15
|
|
|
$flags = 0 |
16
|
|
|
) { |
17
|
46 |
|
if ($new !== false) { |
18
|
1 |
|
trigger_error('Argument $new is no longer supported in PHP > 7', E_USER_WARNING); |
19
|
|
|
} |
20
|
|
|
|
21
|
45 |
|
$hash = sha1($hostname . $username . $flags); |
22
|
45 |
|
if ($hostname{1} != ':' && isset(\Dshafik\MySQL::$connections[$hash])) { |
23
|
10 |
|
\Dshafik\MySQL::$last_connection = \Dshafik\MySQL::$connections[$hash]['conn']; |
24
|
10 |
|
\Dshafik\MySQL::$connections[$hash]['refcount'] += 1; |
25
|
10 |
|
return \Dshafik\MySQL::$connections[$hash]['conn']; |
26
|
|
|
} |
27
|
|
|
|
28
|
36 |
|
if ($flags === 0) { |
29
|
34 |
|
\Dshafik\MySQL::$last_connection = $conn = mysqli_connect($hostname, $username, $password); |
30
|
33 |
|
$conn->hash = $hash; |
31
|
33 |
|
\Dshafik\MySQL::$connections[$hash] = ['refcount' => 1, 'conn' => $conn]; |
32
|
|
|
|
33
|
33 |
|
return $conn; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
try { |
37
|
2 |
|
\Dshafik\MySQL::$last_connection = $conn = mysqli_init(); |
38
|
|
|
|
39
|
2 |
|
mysqli_real_connect( |
40
|
|
|
$conn, |
41
|
|
|
$hostname, |
42
|
|
|
$username, |
43
|
|
|
$password, |
44
|
2 |
|
'', |
45
|
2 |
|
null, |
46
|
2 |
|
'', |
47
|
|
|
$flags |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
// @codeCoverageIgnoreStart |
51
|
|
|
// PHPUnit turns the warning from mysqli_real_connect into an exception, so this never runs |
52
|
|
|
if ($conn === false) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
// @codeCoverageIgnoreEnd |
56
|
|
|
|
57
|
1 |
|
$conn->hash = $hash; |
58
|
1 |
|
\Dshafik\MySQL::$connections[$hash] = ['refcount' => 1, 'conn' => $conn]; |
59
|
|
|
|
60
|
1 |
|
return $conn; |
61
|
1 |
|
} catch (\Throwable $e) { |
62
|
1 |
|
trigger_error($e->getMessage(), E_USER_WARNING); |
63
|
|
|
// @codeCoverageIgnoreStart |
64
|
|
|
// PHPUnit turns the warning into an exception, so this never runs |
65
|
|
|
return false; |
66
|
|
|
// @codeCoverageIgnoreEnd |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
function mysql_pconnect( |
71
|
|
|
$hostname = null, |
72
|
|
|
$username = null, |
73
|
|
|
$password = null, |
74
|
|
|
$flags = 0 |
75
|
|
|
) { |
76
|
1 |
|
$hostname = 'p:' . $hostname; |
77
|
1 |
|
return mysql_connect($hostname, $username, $password, false, $flags); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
function mysql_close(\mysqli $link = null) |
81
|
|
|
{ |
82
|
47 |
|
$isDefault = ($link === null); |
83
|
|
|
|
84
|
47 |
|
$link = \Dshafik\MySQL::getConnection($link, __FUNCTION__); |
85
|
47 |
|
if ($link === null) { |
86
|
|
|
// @codeCoverageIgnoreStart |
87
|
|
|
// PHPUnit Warning -> Exception |
88
|
|
|
return false; |
89
|
|
|
// @codeCoverageIgnoreEnd |
90
|
|
|
} |
91
|
|
|
|
92
|
47 |
|
if (isset(\Dshafik\MySQL::$connections[$link->hash])) { |
93
|
43 |
|
\Dshafik\MySQL::$connections[$link->hash]['refcount'] -= 1; |
94
|
|
|
} |
95
|
|
|
|
96
|
47 |
|
$return = true; |
97
|
47 |
|
if (\Dshafik\MySQL::$connections[$link->hash]['refcount'] == 0) { |
98
|
38 |
|
$return = mysqli_close($link); |
99
|
38 |
|
unset(\Dshafik\MySQL::$connections[$link->hash]); |
100
|
|
|
} |
101
|
|
|
|
102
|
47 |
|
if ($isDefault) { |
103
|
47 |
|
Dshafik\MySQL::$last_connection = null; |
104
|
|
|
} |
105
|
|
|
|
106
|
47 |
|
return $return; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
function mysql_select_db($databaseName, \mysqli $link = null) |
110
|
|
|
{ |
111
|
37 |
|
$link = \Dshafik\MySQL::getConnection($link); |
112
|
|
|
|
113
|
37 |
|
return mysqli_query( |
114
|
|
|
$link, |
115
|
37 |
|
"USE " . mysqli_real_escape_string($link, $databaseName) |
116
|
37 |
|
) !== false; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function mysql_query($query, \mysqli $link = null) |
120
|
|
|
{ |
121
|
40 |
|
return mysqli_query(\Dshafik\MySQL::getConnection($link), $query); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function mysql_unbuffered_query($query, \mysqli $link = null) |
125
|
|
|
{ |
126
|
4 |
|
$link = \Dshafik\MySQL::getConnection($link); |
127
|
4 |
|
if (mysqli_real_query($link, $query)) { |
128
|
3 |
|
return mysqli_use_result($link); |
129
|
|
|
} |
130
|
|
|
|
131
|
1 |
|
return false; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
function mysql_db_query($databaseName, $query, \mysqli $link = null) |
135
|
|
|
{ |
136
|
2 |
|
if (mysql_select_db($databaseName, $link)) { |
137
|
1 |
|
return mysql_query($query, $link); |
138
|
|
|
} |
139
|
1 |
|
return false; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
function mysql_list_dbs(\mysqli $link = null) |
143
|
|
|
{ |
144
|
1 |
|
return mysql_query("SHOW DATABASES", $link); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function mysql_list_tables($databaseName, \mysqli $link = null) |
148
|
|
|
{ |
149
|
2 |
|
$link = \Dshafik\MySQL::getConnection($link); |
150
|
2 |
|
return mysql_query("SHOW TABLES FROM " . mysql_real_escape_string($databaseName, $link), $link); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
function mysql_list_fields($databaseName, $tableName, \mysqli $link = null) |
154
|
|
|
{ |
155
|
2 |
|
$link = \Dshafik\MySQL::getConnection($link); |
156
|
2 |
|
$result = mysql_query( |
157
|
|
|
"SHOW COLUMNS FROM " . |
158
|
2 |
|
mysqli_real_escape_string($link, $databaseName) . "." . |
159
|
2 |
|
mysqli_real_escape_string($link, $tableName), |
160
|
|
|
$link |
161
|
|
|
); |
162
|
|
|
|
163
|
2 |
|
if ($result instanceof \mysqli_result) { |
164
|
1 |
|
$result->table = $tableName; |
165
|
1 |
|
return $result; |
166
|
|
|
} |
167
|
|
|
|
168
|
1 |
|
trigger_error("mysql_list_fields(): Unable to save MySQL query result", E_USER_WARNING); |
169
|
|
|
return false; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
function mysql_list_processes(\mysqli $link = null) |
173
|
|
|
{ |
174
|
|
|
return mysql_query("SHOW PROCESSLIST", $link); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
function mysql_error(\mysqli $link = null) |
178
|
|
|
{ |
179
|
23 |
|
return mysqli_error(\Dshafik\MySQL::getConnection($link)); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
function mysql_errno(\mysqli $link = null) |
183
|
|
|
{ |
184
|
1 |
|
return mysqli_errno(\Dshafik\MySQL::getConnection($link)); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
function mysql_affected_rows(\mysqli $link = null) |
188
|
|
|
{ |
189
|
1 |
|
return mysqli_affected_rows(\Dshafik\MySQL::getConnection($link)); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
function mysql_insert_id($link = null) /*|*/ |
193
|
|
|
{ |
194
|
1 |
|
return mysqli_insert_id(\Dshafik\MySQL::getConnection($link)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
function mysql_result(\mysqli_result $result, $row, $field = 0) |
198
|
|
|
{ |
199
|
5 |
|
if (!mysqli_data_seek($result, $row)) { |
200
|
1 |
|
trigger_error( |
201
|
|
|
sprintf( |
202
|
1 |
|
"mysql_result(): Unable to jump to row %d on MySQL result index %s", |
203
|
|
|
$row, |
204
|
|
|
spl_object_hash($result) |
205
|
|
|
), |
206
|
1 |
|
E_USER_WARNING |
207
|
|
|
); |
208
|
|
|
// @codeCoverageIgnoreStart |
209
|
|
|
return false; |
210
|
|
|
// @codeCoverageIgnoreEnd |
211
|
|
|
} |
212
|
|
|
|
213
|
4 |
|
$found = true; |
214
|
4 |
|
if (strpos($field, ".") !== false) { |
215
|
2 |
|
list($table, $name) = explode(".", $field); |
216
|
2 |
|
$i = 0; |
217
|
2 |
|
$found = false; |
218
|
2 |
|
while ($column = mysqli_fetch_field($result)) { |
219
|
2 |
|
if ($column->table == $table && $column->name == $name) { |
220
|
1 |
|
$field = $i; |
221
|
1 |
|
$found = true; |
222
|
1 |
|
break; |
223
|
|
|
} |
224
|
1 |
|
$i++; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
4 |
|
$row = mysql_fetch_array($result); |
229
|
4 |
|
if ($found && isset($row[$field])) { |
230
|
2 |
|
return $row[$field]; |
231
|
|
|
} |
232
|
|
|
|
233
|
2 |
|
trigger_error( |
234
|
|
|
sprintf( |
235
|
2 |
|
"%s(): %s not found in MySQL result index %s", |
236
|
2 |
|
__FUNCTION__, |
237
|
|
|
$field, |
238
|
|
|
spl_object_hash($result) |
239
|
|
|
), |
240
|
2 |
|
E_USER_WARNING |
241
|
|
|
); |
242
|
|
|
// @codeCoverageIgnoreStart |
243
|
|
|
return false; |
244
|
|
|
// @codeCoverageIgnoreEnd |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
function mysql_num_rows(\mysqli_result $result) |
248
|
|
|
{ |
249
|
7 |
|
$previous = error_reporting(0); |
250
|
7 |
|
$rows = mysqli_num_rows($result); |
251
|
7 |
|
error_reporting($previous); |
252
|
|
|
|
253
|
7 |
|
return $rows; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
function mysql_num_fields($result) |
257
|
|
|
{ |
258
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
259
|
|
|
return false; |
260
|
|
|
} |
261
|
1 |
|
return mysqli_num_fields($result); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
function mysql_fetch_row($result) /* : array|null */ |
265
|
|
|
{ |
266
|
4 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
267
|
|
|
return false; |
268
|
|
|
} |
269
|
4 |
|
return mysqli_fetch_row($result); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
function mysql_fetch_array($result) /* : array|null */ |
273
|
|
|
{ |
274
|
5 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
275
|
|
|
return false; |
276
|
|
|
} |
277
|
5 |
|
return mysqli_fetch_array($result); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
function mysql_fetch_assoc($result) /* : array|null */ |
281
|
|
|
{ |
282
|
5 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
283
|
|
|
return false; |
284
|
|
|
} |
285
|
5 |
|
return mysqli_fetch_assoc($result); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
function mysql_fetch_object($result, $class = null, array $params = []) /* : object|null */ |
289
|
|
|
{ |
290
|
1 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
291
|
|
|
return false; |
292
|
|
|
} |
293
|
|
|
|
294
|
1 |
|
if ($class == null) { |
295
|
1 |
|
return mysqli_fetch_object($result); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
return mysqli_fetch_object($result, $class, $params); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
function mysql_data_seek($result, $offset) |
302
|
|
|
{ |
303
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
304
|
|
|
return false; |
305
|
|
|
} |
306
|
|
|
return mysqli_data_seek($result, $offset); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
function mysql_fetch_lengths($result) /* : array|*/ |
310
|
|
|
{ |
311
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
312
|
|
|
return false; |
313
|
|
|
} |
314
|
|
|
return mysqli_fetch_lengths($result); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
function mysql_fetch_field($result) /* : object|*/ |
318
|
|
|
{ |
319
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
320
|
|
|
return false; |
321
|
|
|
} |
322
|
|
|
return mysqli_fetch_field($result); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
function mysql_field_seek($result, $field) |
326
|
|
|
{ |
327
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
328
|
|
|
return false; |
329
|
|
|
} |
330
|
|
|
return mysqli_field_seek($result, $field); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
function mysql_free_result($result) |
334
|
|
|
{ |
335
|
1 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
336
|
|
|
return false; |
337
|
|
|
} |
338
|
1 |
|
return mysqli_free_result($result); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
function mysql_field_name($result, $field) |
342
|
|
|
{ |
343
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
344
|
|
|
return false; |
345
|
|
|
} |
346
|
2 |
|
return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'name'); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
function mysql_field_table($result, $field) |
350
|
|
|
{ |
351
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
352
|
|
|
return false; |
353
|
|
|
} |
354
|
2 |
|
return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'table'); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
function mysql_field_len($result, $field) |
358
|
|
|
{ |
359
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
360
|
|
|
return false; |
361
|
|
|
} |
362
|
2 |
|
return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'len'); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
function mysql_field_type($result, $field) |
366
|
|
|
{ |
367
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
368
|
|
|
return false; |
369
|
|
|
} |
370
|
2 |
|
return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'type'); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
function mysql_field_flags($result, $field) |
374
|
|
|
{ |
375
|
2 |
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
376
|
|
|
return false; |
377
|
|
|
} |
378
|
2 |
|
return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'flags'); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
function mysql_escape_string($unescapedString) |
382
|
|
|
{ |
383
|
|
|
return mysql_real_escape_string($unescapedString, null); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
function mysql_real_escape_string($unescapedString, \mysqli $link = null) |
387
|
|
|
{ |
388
|
2 |
|
return mysqli_escape_string(\Dshafik\MySQL::getConnection($link), $unescapedString); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
function mysql_stat(\mysqli $link = null) |
392
|
|
|
{ |
393
|
|
|
return mysqli_stat(\Dshafik\MySQL::getConnection($link)); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
function mysql_thread_id(\mysqli $link = null) |
397
|
|
|
{ |
398
|
|
|
return mysqli_thread_id(\Dshafik\MySQL::getConnection($link)); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
function mysql_client_encoding(\mysqli $link = null) |
402
|
|
|
{ |
403
|
|
|
return mysqli_character_set_name(\Dshafik\MySQL::getConnection($link)); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
function mysql_ping(\mysqli $link = null) |
407
|
|
|
{ |
408
|
|
|
return mysqli_ping($link); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
function mysql_get_client_info(\mysqli $link = null) |
412
|
|
|
{ |
413
|
|
|
return mysqli_get_client_info(\Dshafik\MySQL::getConnection($link)); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
function mysql_get_host_info(\mysqli $link = null) |
417
|
|
|
{ |
418
|
|
|
return mysqli_get_host_info(\Dshafik\MySQL::getConnection($link)); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
function mysql_get_proto_info(\mysqli $link = null) |
422
|
|
|
{ |
423
|
|
|
return mysqli_get_proto_info(\Dshafik\MySQL::getConnection($link)); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
function mysql_get_server_info(\mysqli $link = null) |
427
|
|
|
{ |
428
|
|
|
return mysqli_get_server_info(\Dshafik\MySQL::getConnection($link)); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
function mysql_info(\mysqli $link = null) |
432
|
|
|
{ |
433
|
|
|
return mysqli_info(\Dshafik\MySQL::getConnection($link)); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
function mysql_set_charset($charset, \mysqli $link = null) |
437
|
|
|
{ |
438
|
|
|
return mysqli_set_charset(\Dshafik\MySQL::getConnection($link), $charset); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
function mysql_db_name($result) |
442
|
|
|
{ |
443
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
444
|
|
|
return false; |
445
|
|
|
} |
446
|
|
|
return mysqli_fetch_row($result)['Database']; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
function mysql_table_name($result) |
450
|
|
|
{ |
451
|
|
|
if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
452
|
|
|
return false; |
453
|
|
|
} |
454
|
|
|
return mysqli_fetch_row($result)['Table']; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/* Aliases */ |
458
|
|
|
|
459
|
|
|
function mysql_fieldname(... $args) |
460
|
|
|
{ |
461
|
|
|
return mysql_field_name(... $args); |
|
|
|
|
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
function mysql_fieldtable(... $args) |
465
|
|
|
{ |
466
|
|
|
return mysql_field_table(... $args); |
|
|
|
|
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
function mysql_fieldlen(... $args) |
470
|
|
|
{ |
471
|
|
|
return mysql_field_len(... $args); |
|
|
|
|
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
function mysql_fieldtype(... $args) |
475
|
|
|
{ |
476
|
|
|
return mysql_field_type(... $args); |
|
|
|
|
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
function mysql_fieldflags(... $args) |
480
|
|
|
{ |
481
|
|
|
return mysql_field_flags(... $args); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
function mysql_selectdb(... $args) |
485
|
|
|
{ |
486
|
|
|
return mysql_select_db(... $args); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
function mysql_freeresult(... $args) |
490
|
|
|
{ |
491
|
|
|
return mysql_free_result(... $args); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
function mysql_numfields(... $args) |
495
|
|
|
{ |
496
|
|
|
return mysql_num_fields(... $args); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
function mysql_numrows(... $args) |
500
|
|
|
{ |
501
|
|
|
return mysql_num_rows(... $args); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
function mysql_listdbs(... $args) |
505
|
|
|
{ |
506
|
|
|
return mysql_list_dbs(... $args); |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
function mysql_listtables(... $args) |
510
|
|
|
{ |
511
|
|
|
return mysql_list_tables(... $args); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
function mysql_listfields(... $args) |
515
|
|
|
{ |
516
|
|
|
return mysql_list_fields(... $args); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
function mysql_dbname(... $args) |
520
|
|
|
{ |
521
|
|
|
return mysql_db_name(... $args); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
function mysql_tablename(... $args) |
525
|
|
|
{ |
526
|
|
|
return mysql_table_name(... $args); |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
namespace Dshafik { |
532
|
|
|
|
533
|
|
|
class MySQL |
534
|
|
|
{ |
535
|
|
|
public static $last_connection = null; |
536
|
|
|
public static $connections = []; |
537
|
|
|
|
538
|
47 |
|
public static function getConnection($link = null, $func = null) |
539
|
|
|
{ |
540
|
47 |
|
if ($link !== null) { |
541
|
7 |
|
return $link; |
542
|
|
|
} |
543
|
|
|
|
544
|
47 |
|
if (static::$last_connection === null) { |
545
|
4 |
|
$err = "A link to the server could not be established"; |
546
|
4 |
|
if ($func !== null) { |
547
|
4 |
|
$err = $func . "(): no MySQL-Link resource supplied"; |
548
|
|
|
} |
549
|
4 |
|
trigger_error($err, E_USER_WARNING); |
550
|
4 |
|
return false; |
551
|
|
|
} |
552
|
|
|
|
553
|
44 |
|
return static::$last_connection; |
554
|
|
|
} |
555
|
|
|
|
556
|
6 |
|
public static function mysqlFieldInfo(\mysqli_result $result, $field, $what) |
557
|
|
|
{ |
558
|
|
|
try { |
559
|
6 |
|
$field = mysqli_fetch_field_direct($result, $field); |
560
|
5 |
|
} catch (\Exception $e) { |
561
|
5 |
|
trigger_error( |
562
|
|
|
sprintf( |
563
|
5 |
|
"mysql_field_%s(): Field %d is invalid for MySQL result index %s", |
564
|
|
|
$what, |
565
|
|
|
$field, |
566
|
|
|
spl_object_hash($result) |
567
|
|
|
), |
568
|
5 |
|
E_USER_WARNING |
569
|
|
|
); |
570
|
|
|
// @codeCoverageIgnoreStart |
571
|
|
|
// PHPUnit turns the warning into an exception, so this never runs |
572
|
|
|
return false; |
573
|
|
|
// @codeCoverageIgnoreEnd |
574
|
|
|
} |
575
|
|
|
|
576
|
1 |
|
if ($what == 'name' || $what == 'table') { |
577
|
1 |
|
return $field->{$what}; |
578
|
|
|
} |
579
|
|
|
|
580
|
1 |
|
if ($what == 'len') { |
581
|
1 |
|
return $field->length; |
582
|
|
|
} |
583
|
|
|
|
584
|
1 |
|
if ($what == 'type') { |
585
|
1 |
|
return static::getFieldType($field->type); |
586
|
|
|
} |
587
|
|
|
|
588
|
1 |
|
if ($what == 'flags') { |
589
|
1 |
|
return static::getFieldFlags($field->flags); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
return false; |
593
|
|
|
} |
594
|
|
|
|
595
|
24 |
|
public static function checkValidResult($result, $function) |
596
|
|
|
{ |
597
|
24 |
|
if (!($result instanceof \mysqli_result)) { |
598
|
1 |
|
trigger_error( |
599
|
1 |
|
$function . "() expects parameter 1 to be resource, " . gettype($result) . " given", |
600
|
1 |
|
E_USER_WARNING |
601
|
|
|
); |
602
|
|
|
return false; |
603
|
|
|
} |
604
|
23 |
|
} |
605
|
|
|
|
606
|
1 |
|
protected static function getFieldFlags($what) |
607
|
|
|
{ |
608
|
|
|
// Order of flags taken from http://lxr.php.net/xref/PHP_5_6/ext/mysql/php_mysql.c#2507 |
609
|
|
|
|
610
|
1 |
|
$flags = []; |
611
|
1 |
|
if ($what & MYSQLI_NOT_NULL_FLAG) { |
612
|
1 |
|
$flags[] = "not_null"; |
613
|
|
|
} |
614
|
|
|
|
615
|
1 |
|
if ($what & MYSQLI_PRI_KEY_FLAG) { |
616
|
1 |
|
$flags[] = "primary_key"; |
617
|
|
|
} |
618
|
|
|
|
619
|
1 |
|
if ($what & MYSQLI_UNIQUE_KEY_FLAG) { |
620
|
1 |
|
$flags[] = "unique_key"; |
621
|
|
|
} |
622
|
|
|
|
623
|
1 |
|
if ($what & MYSQLI_MULTIPLE_KEY_FLAG) { |
624
|
1 |
|
$flags[] = "multiple_key"; |
625
|
|
|
} |
626
|
|
|
|
627
|
1 |
|
if ($what & MYSQLI_BLOB_FLAG) { |
628
|
1 |
|
$flags[] = "blob"; |
629
|
|
|
} |
630
|
|
|
|
631
|
1 |
|
if ($what & MYSQLI_UNSIGNED_FLAG) { |
632
|
|
|
$flags[] = "unsigned"; |
633
|
|
|
} |
634
|
|
|
|
635
|
1 |
|
if ($what & MYSQLI_ZEROFILL_FLAG) { |
636
|
|
|
$flags[] = "zerofill"; |
637
|
|
|
} |
638
|
|
|
|
639
|
1 |
|
if ($what & MYSQLI_BINARY_FLAG) { |
640
|
|
|
$flags[] = "binary"; |
641
|
|
|
} |
642
|
|
|
|
643
|
1 |
|
if ($what & MYSQLI_ENUM_FLAG) { |
644
|
1 |
|
$flags[] = "enum"; |
645
|
|
|
} |
646
|
|
|
|
647
|
1 |
|
if ($what & MYSQLI_SET_FLAG) { |
648
|
1 |
|
$flags[] = "set"; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
|
652
|
1 |
|
if ($what & MYSQLI_AUTO_INCREMENT_FLAG) { |
653
|
1 |
|
$flags[] = "auto_increment"; |
654
|
|
|
} |
655
|
|
|
|
656
|
1 |
|
if ($what & MYSQLI_TIMESTAMP_FLAG) { |
657
|
|
|
$flags[] = "timestamp"; |
658
|
|
|
} |
659
|
|
|
|
660
|
1 |
|
return implode(" ", $flags); |
661
|
|
|
} |
662
|
|
|
|
663
|
1 |
|
protected static function getFieldType($what) |
664
|
|
|
{ |
665
|
|
|
switch ($what) { |
666
|
1 |
|
case MYSQLI_TYPE_STRING: |
667
|
1 |
|
case MYSQLI_TYPE_VAR_STRING: |
668
|
1 |
|
case MYSQLI_TYPE_ENUM: |
669
|
1 |
|
case MYSQLI_TYPE_SET: |
670
|
1 |
|
return "string"; |
671
|
1 |
|
case MYSQLI_TYPE_LONG: |
672
|
1 |
|
case MYSQLI_TYPE_TINY: |
673
|
1 |
|
case MYSQLI_TYPE_SHORT: |
674
|
1 |
|
case MYSQLI_TYPE_INT24: |
675
|
1 |
|
case MYSQLI_TYPE_CHAR: |
676
|
1 |
|
case MYSQLI_TYPE_LONGLONG: |
677
|
1 |
|
return "int"; |
678
|
1 |
|
case MYSQLI_TYPE_DECIMAL: |
679
|
1 |
|
case MYSQLI_TYPE_FLOAT: |
680
|
1 |
|
case MYSQLI_TYPE_DOUBLE: |
681
|
1 |
|
case MYSQLI_TYPE_NEWDECIMAL: |
682
|
|
|
return "real"; |
683
|
1 |
|
case MYSQLI_TYPE_DATETIME: |
684
|
|
|
return "datetime"; |
685
|
1 |
|
case MYSQLI_TYPE_TIMESTAMP: |
686
|
|
|
return "timestamp"; |
687
|
1 |
|
case MYSQLI_TYPE_NEWDATE: |
688
|
1 |
|
case MYSQLI_TYPE_DATE: |
689
|
|
|
return "date"; |
690
|
1 |
|
case MYSQLI_TYPE_TIME: |
691
|
|
|
return "time"; |
692
|
1 |
|
case MYSQLI_TYPE_YEAR: |
693
|
|
|
return "year"; |
694
|
1 |
|
case MYSQLI_TYPE_TINY_BLOB: |
695
|
1 |
|
case MYSQLI_TYPE_MEDIUM_BLOB: |
696
|
1 |
|
case MYSQLI_TYPE_LONG_BLOB: |
697
|
1 |
|
case MYSQLI_TYPE_BLOB: |
698
|
1 |
|
return "blob"; |
699
|
|
|
case MYSQLI_TYPE_NULL: |
700
|
|
|
return "null"; |
701
|
|
|
case MYSQLI_TYPE_GEOMETRY: |
702
|
|
|
return "geometry"; |
703
|
|
|
case MYSQLI_TYPE_INTERVAL: |
704
|
|
|
case MYSQLI_TYPE_BIT: |
705
|
|
|
default: |
706
|
|
|
return "unknown"; |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
} |
710
|
|
|
} |
711
|
|
|
|
This check looks for function calls that miss required arguments.