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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
<?php /* $Id: mysqli.dbi.lib.php,v 2.29 2004/08/02 00:46:22 lem9 Exp $ */ // vim: expandtab sw=4 ts=4 sts=4:
/** * Interface to the improved MySQL extension (MySQLi) */
/** * Loads the MySQLi extension if it is not loaded yet */ if (!@function_exists('mysqli_connect')) { PMA_dl('mysqli'); }
// check whether mysql is available if (!@function_exists('mysqli_connect')) { require_once('./libraries/header_http.inc.php'); echo sprintf($strCantLoad, 'mysqli') . '<br />' . "\n" . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n"; exit; }
// MySQL client API if (!defined('PMA_MYSQL_CLIENT_API')) { $client_api = explode('.', mysqli_get_client_info()); define('PMA_MYSQL_CLIENT_API', (int)sprintf('%d%02d%02d', $client_api[0], $client_api[1], intval($client_api[2]))); unset($client_api); }
// Constants from mysql_com.h of MySQL 4.1.3
define('NOT_NULL_FLAG', 1); define('PRI_KEY_FLAG', 2); define('UNIQUE_KEY_FLAG', 4); define('MULTIPLE_KEY_FLAG', 8); define('BLOB_FLAG', 16); define('UNSIGNED_FLAG', 32); define('ZEROFILL_FLAG', 64); define('BINARY_FLAG', 128); define('ENUM_FLAG', 256); define('AUTO_INCREMENT_FLAG', 512); define('TIMESTAMP_FLAG', 1024); define('SET_FLAG', 2048); define('NUM_FLAG', 32768); define('PART_KEY_FLAG', 16384); define('UNIQUE_FLAG', 65536);
function PMA_DBI_connect($user, $password) { global $cfg, $php_errormsg;
$server_port = (empty($cfg['Server']['port'])) ? FALSE : (int) $cfg['Server']['port'];
if (strtolower($cfg['Server']['connect_type']) == 'tcp') { $cfg['Server']['socket'] = ''; }
$server_socket = (empty($cfg['Server']['socket'])) ? FALSE : $cfg['Server']['socket'];
if ($server_socket) { $link = @mysqli_connect($cfg['Server']['host'], $user, $password, FALSE, $server_port, $server_socket); } else { // Omit the last parameter to enable connection to the default socket $link = @mysqli_connect($cfg['Server']['host'], $user, $password, FALSE, $server_port); }
if (empty($link)) { PMA_auth_fails(); } // end if
PMA_DBI_postConnect($link);
return $link; }
function PMA_DBI_select_db($dbname, $link = NULL) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } if (PMA_MYSQL_INT_VERSION < 40100) { $dbname = PMA_convert_charset($dbname); } return mysqli_select_db($link, $dbname); }
function PMA_DBI_try_query($query, $link = NULL, $options = 0) { if ($options == ($options | PMA_DBI_QUERY_STORE)) { $method = MYSQLI_STORE_RESULT; } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) { $method = MYSQLI_USE_RESULT; } else { $method = MYSQLI_USE_RESULT; }
if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } if (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION < 40100) { $query = PMA_convert_charset($query); } return mysqli_query($link, $query, $method); }
// The following function is meant for internal use only. // Do not call it from outside this library! function PMA_mysqli_fetch_array($result, $type = FALSE) { global $cfg, $allow_recoding, $charset, $convcharset;
if ($type != FALSE) { $data = @mysqli_fetch_array($result, $type); } else { $data = @mysqli_fetch_array($result); }
/* No data returned => do not touch it */ if (! $data) return $data; if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100 || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { /* No recoding -> return data as we got them */ return $data; } else { $ret = array(); $num = mysqli_num_fields($result); $fields = mysqli_fetch_fields($result); $i = 0; for ($i = 0; $i < $num; $i++) { if (!$meta) { /* No meta information available -> we guess that it should be converted */ if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]); if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]); } else { /* Meta information available -> check type of field and convert it according to the type */ if (stristr($fields[$i]->type, 'BLOB') || stristr($fields[$i]->type, 'BINARY')) { if (isset($data[$i])) $ret[$i] = $data[$i]; if (isset($data[$fields[$i]->name])) $ret[PMA_convert_display_charset($fields[$i]->name)] = $data[$fields[$i]->name]; } else { if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]); if (isset($data[$fields[$i]->name])) $ret[PMA_convert_display_charset($fields[$i]->name)] = PMA_convert_display_charset($data[$fields[$i]->name]); } } } return $ret; } }
function PMA_DBI_fetch_array($result) { return PMA_mysqli_fetch_array($result, MYSQLI_BOTH); }
function PMA_DBI_fetch_assoc($result) { return PMA_mysqli_fetch_array($result, MYSQLI_ASSOC); }
function PMA_DBI_fetch_row($result) { return PMA_mysqli_fetch_array($result, MYSQLI_NUM); }
function PMA_DBI_free_result($result) { return @mysqli_free_result($result); }
function PMA_DBI_getError($link = NULL) { unset($GLOBALS['errno']); if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; // Do not stop now. We still can get the error code // with mysqli_connect_errno() // } else { // return FALSE; } }
if (mysqli_connect_errno()) { $error = mysqli_connect_errno(); $error_message = mysqli_connect_error(); } elseif (mysqli_errno($link)) { $error = mysqli_errno($link); $error_message = mysqli_error($link); }
// keep the error number for further check after the call to PMA_DBI_getError() if (!empty($error)) { $GLOBALS['errno'] = $error; } else { return FALSE; }
if ($error && $error == 2002) { $error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding']; } elseif ($error && defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) { $error = '#' . ((string) $error) . ' - ' . $error_message; } elseif ($error) { $error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset($error_message); } return $error; }
function PMA_DBI_close($link = NULL) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } return @mysqli_close($link); }
function PMA_DBI_num_rows($result) { return @mysqli_num_rows($result); }
function PMA_DBI_insert_id($link = '') { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } return mysqli_insert_id($link); }
function PMA_DBI_affected_rows($link = NULL) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } return mysqli_affected_rows($link); }
function PMA_DBI_get_fields_meta($result) { // Build an associative array for a type look up $typeAr = Array(); $typeAr[MYSQLI_TYPE_DECIMAL] = 'real'; $typeAr[MYSQLI_TYPE_TINY] = 'int'; $typeAr[MYSQLI_TYPE_SHORT] = 'int'; $typeAr[MYSQLI_TYPE_LONG] = 'int'; $typeAr[MYSQLI_TYPE_FLOAT] = 'real'; $typeAr[MYSQLI_TYPE_DOUBLE] = 'real'; $typeAr[MYSQLI_TYPE_NULL] = 'null'; $typeAr[MYSQLI_TYPE_TIMESTAMP] = 'timestamp'; $typeAr[MYSQLI_TYPE_LONGLONG] = 'int'; $typeAr[MYSQLI_TYPE_INT24] = 'int'; $typeAr[MYSQLI_TYPE_DATE] = 'date'; $typeAr[MYSQLI_TYPE_TIME] = 'time'; $typeAr[MYSQLI_TYPE_DATETIME] = 'datetime'; $typeAr[MYSQLI_TYPE_YEAR] = 'year'; $typeAr[MYSQLI_TYPE_NEWDATE] = 'date'; $typeAr[MYSQLI_TYPE_ENUM] = 'unknown'; $typeAr[MYSQLI_TYPE_SET] = 'unknown'; $typeAr[MYSQLI_TYPE_TINY_BLOB] = 'blob'; $typeAr[MYSQLI_TYPE_MEDIUM_BLOB] = 'blob'; $typeAr[MYSQLI_TYPE_LONG_BLOB] = 'blob'; $typeAr[MYSQLI_TYPE_BLOB] = 'blob'; $typeAr[MYSQLI_TYPE_VAR_STRING] = 'string'; $typeAr[MYSQLI_TYPE_STRING] = 'string'; $typeAr[MYSQLI_TYPE_CHAR] = 'string'; $typeAr[MYSQLI_TYPE_GEOMETRY] = 'unknown';
$fields = mysqli_fetch_fields($result); foreach ($fields as $k => $field) { $fields[$k]->type = $typeAr[$fields[$k]->type]; $fields[$k]->flags = PMA_DBI_field_flags($result, $k); // Enhance the field objects for mysql-extension compatibilty $flags = explode(' ', $fields[$k]->flags); array_unshift($flags, 'dummy'); $fields[$k]->multiple_key = (int)(array_search('multiple_key', $flags, true) > 0); $fields[$k]->primary_key = (int)(array_search('primary_key', $flags, true) > 0); $fields[$k]->unique_key = (int)(array_search('unique_key', $flags, true) > 0); $fields[$k]->not_null = (int)(array_search('not_null', $flags, true) > 0); $fields[$k]->unsigned = (int)(array_search('unsigned', $flags, true) > 0); $fields[$k]->zerofill = (int)(array_search('zerofill', $flags, true) > 0); $fields[$k]->numeric = (int)(array_search('num', $flags, true) > 0); $fields[$k]->blob = (int)(array_search('blob', $flags, true) > 0); } return $fields; }
function PMA_DBI_num_fields($result) { return mysqli_num_fields($result); }
function PMA_DBI_field_len($result, $i) { $info = mysqli_fetch_field_direct($result, $i); // stdClass::$length will be integrated in // mysqli-ext when mysql4.1 has been released. return @$info->length; }
function PMA_DBI_field_name($result, $i) { $info = mysqli_fetch_field_direct($result, $i); return $info->name; }
function PMA_DBI_field_flags($result, $i) { $f = mysqli_fetch_field_direct($result, $i); $f = $f->flags; $flags = ''; if ($f & UNIQUE_FLAG) { $flags .= 'unique ';} if ($f & NUM_FLAG) { $flags .= 'num ';} if ($f & PART_KEY_FLAG) { $flags .= 'part_key ';} if ($f & SET_FLAG) { $flags .= 'set ';} if ($f & TIMESTAMP_FLAG) { $flags .= 'timestamp ';} if ($f & AUTO_INCREMENT_FLAG) { $flags .= 'auto_increment ';} if ($f & ENUM_FLAG) { $flags .= 'enum ';} if ($f & BINARY_FLAG) { $flags .= 'binary ';} if ($f & ZEROFILL_FLAG) { $flags .= 'zerofill ';} if ($f & UNSIGNED_FLAG) { $flags .= 'unsigned ';} if ($f & BLOB_FLAG) { $flags .= 'blob ';} if ($f & MULTIPLE_KEY_FLAG) { $flags .= 'multiple_key ';} if ($f & UNIQUE_KEY_FLAG) { $flags .= 'unique_key ';} if ($f & PRI_KEY_FLAG) { $flags .= 'primary_key ';} if ($f & NOT_NULL_FLAG) { $flags .= 'not_null ';} return PMA_convert_display_charset(trim($flags)); }
?>
|