1 | <?php |
---|
2 | /* |
---|
3 | V4.51 29 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved. |
---|
4 | Released under both BSD license and Lesser GPL library license. |
---|
5 | Whenever there is any discrepancy between the two licenses, |
---|
6 | the BSD license will take precedence. |
---|
7 | Set tabs to 8. |
---|
8 | |
---|
9 | MySQL code that does not support transactions. Use mysqlt if you need transactions. |
---|
10 | Requires mysql client. Works on Windows and Unix. |
---|
11 | |
---|
12 | 21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl) |
---|
13 | Based on adodb 3.40 |
---|
14 | */ |
---|
15 | |
---|
16 | // security - hide paths |
---|
17 | //if (!defined('ADODB_DIR')) die(); |
---|
18 | |
---|
19 | if (! defined("_ADODB_MYSQLI_LAYER")) { |
---|
20 | define("_ADODB_MYSQLI_LAYER", 1 ); |
---|
21 | |
---|
22 | class ADODB_mysqli extends ADOConnection { |
---|
23 | var $databaseType = 'mysqli'; |
---|
24 | var $dataProvider = 'native'; |
---|
25 | var $hasInsertID = true; |
---|
26 | var $hasAffectedRows = true; |
---|
27 | var $metaTablesSQL = "SHOW TABLES"; |
---|
28 | var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; |
---|
29 | var $fmtTimeStamp = "'Y-m-d H:i:s'"; |
---|
30 | var $hasLimit = true; |
---|
31 | var $hasMoveFirst = true; |
---|
32 | var $hasGenID = true; |
---|
33 | var $isoDates = true; // accepts dates in ISO format |
---|
34 | var $sysDate = 'CURDATE()'; |
---|
35 | var $sysTimeStamp = 'NOW()'; |
---|
36 | var $hasTransactions = false; |
---|
37 | var $forceNewConnect = false; |
---|
38 | var $poorAffectedRows = true; |
---|
39 | var $clientFlags = 0; |
---|
40 | var $substr = "substring"; |
---|
41 | var $port = false; |
---|
42 | var $socket = false; |
---|
43 | var $_bindInputArray = false; |
---|
44 | var $nameQuote = '`'; /// string to use to quote identifiers and names |
---|
45 | |
---|
46 | function ADODB_mysqli() |
---|
47 | { |
---|
48 | if(!extension_loaded("mysqli")) |
---|
49 | trigger_error("You must have the MySQLi extension.", E_USER_ERROR); |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | // returns true or false |
---|
55 | // To add: parameter int $port, |
---|
56 | // parameter string $socket |
---|
57 | function _connect($argHostname = NULL, |
---|
58 | $argUsername = NULL, |
---|
59 | $argPassword = NULL, |
---|
60 | $argDatabasename = NULL, $persist=false) |
---|
61 | { |
---|
62 | $this->_connectionID = @mysqli_init(); |
---|
63 | |
---|
64 | if (is_null($this->_connectionID)) { |
---|
65 | // mysqli_init only fails if insufficient memory |
---|
66 | if ($this->debug) |
---|
67 | ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg()); |
---|
68 | return false; |
---|
69 | } |
---|
70 | // Set connection options |
---|
71 | // Not implemented now |
---|
72 | // mysqli_options($this->_connection,,); |
---|
73 | if (mysqli_real_connect($this->_connectionID, |
---|
74 | $argHostname, |
---|
75 | $argUsername, |
---|
76 | $argPassword, |
---|
77 | $argDatabasename, |
---|
78 | $this->port, |
---|
79 | $this->socket, |
---|
80 | $this->clientFlags)) |
---|
81 | { |
---|
82 | if ($argDatabasename) return $this->SelectDB($argDatabasename); |
---|
83 | |
---|
84 | |
---|
85 | return true; |
---|
86 | } |
---|
87 | else { |
---|
88 | if ($this->debug) |
---|
89 | ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); |
---|
90 | return false; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | // returns true or false |
---|
95 | // How to force a persistent connection |
---|
96 | function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
---|
97 | { |
---|
98 | return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true); |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | // When is this used? Close old connection first? |
---|
103 | // In _connect(), check $this->forceNewConnect? |
---|
104 | function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
---|
105 | { |
---|
106 | $this->forceNewConnect = true; |
---|
107 | $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); |
---|
108 | } |
---|
109 | |
---|
110 | function IfNull( $field, $ifNull ) |
---|
111 | { |
---|
112 | return " IFNULL($field, $ifNull) "; // if MySQL |
---|
113 | } |
---|
114 | |
---|
115 | function ServerInfo() |
---|
116 | { |
---|
117 | $arr['description'] = $this->GetOne("select version()"); |
---|
118 | $arr['version'] = ADOConnection::_findvers($arr['description']); |
---|
119 | return $arr; |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | function BeginTrans() |
---|
124 | { |
---|
125 | if ($this->transOff) return true; |
---|
126 | $this->transCnt += 1; |
---|
127 | $this->Execute('SET AUTOCOMMIT=0'); |
---|
128 | $this->Execute('BEGIN'); |
---|
129 | return true; |
---|
130 | } |
---|
131 | |
---|
132 | function CommitTrans($ok=true) |
---|
133 | { |
---|
134 | if ($this->transOff) return true; |
---|
135 | if (!$ok) return $this->RollbackTrans(); |
---|
136 | |
---|
137 | if ($this->transCnt) $this->transCnt -= 1; |
---|
138 | $this->Execute('COMMIT'); |
---|
139 | $this->Execute('SET AUTOCOMMIT=1'); |
---|
140 | return true; |
---|
141 | } |
---|
142 | |
---|
143 | function RollbackTrans() |
---|
144 | { |
---|
145 | if ($this->transOff) return true; |
---|
146 | if ($this->transCnt) $this->transCnt -= 1; |
---|
147 | $this->Execute('ROLLBACK'); |
---|
148 | $this->Execute('SET AUTOCOMMIT=1'); |
---|
149 | return true; |
---|
150 | } |
---|
151 | |
---|
152 | // if magic quotes disabled, use mysql_real_escape_string() |
---|
153 | // From readme.htm: |
---|
154 | // Quotes a string to be sent to the database. The $magic_quotes_enabled |
---|
155 | // parameter may look funny, but the idea is if you are quoting a |
---|
156 | // string extracted from a POST/GET variable, then |
---|
157 | // pass get_magic_quotes_gpc() as the second parameter. This will |
---|
158 | // ensure that the variable is not quoted twice, once by qstr and once |
---|
159 | // by the magic_quotes_gpc. |
---|
160 | // |
---|
161 | //Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc()); |
---|
162 | function qstr($s, $magic_quotes = false) |
---|
163 | { |
---|
164 | if (!$magic_quotes) { |
---|
165 | if (PHP_VERSION >= 5) |
---|
166 | return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'"; |
---|
167 | |
---|
168 | if ($this->replaceQuote[0] == '\\') |
---|
169 | $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); |
---|
170 | return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
---|
171 | } |
---|
172 | // undo magic quotes for " |
---|
173 | $s = str_replace('\\"','"',$s); |
---|
174 | return "'$s'"; |
---|
175 | } |
---|
176 | |
---|
177 | function _insertid() |
---|
178 | { |
---|
179 | // $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID); |
---|
180 | $result = @mysqli_insert_id($this->_connectionID); |
---|
181 | if ($result == -1){ |
---|
182 | if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg()); |
---|
183 | } |
---|
184 | return $result; |
---|
185 | } |
---|
186 | |
---|
187 | // Only works for INSERT, UPDATE and DELETE query's |
---|
188 | function _affectedrows() |
---|
189 | { |
---|
190 | // $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID); |
---|
191 | $result = @mysqli_affected_rows($this->_connectionID); |
---|
192 | if ($result == -1) { |
---|
193 | if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : " . $this->ErrorMsg()); |
---|
194 | } |
---|
195 | return $result; |
---|
196 | } |
---|
197 | |
---|
198 | // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html |
---|
199 | // Reference on Last_Insert_ID on the recommended way to simulate sequences |
---|
200 | var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; |
---|
201 | var $_genSeqSQL = "create table %s (id int not null)"; |
---|
202 | var $_genSeq2SQL = "insert into %s values (%s)"; |
---|
203 | var $_dropSeqSQL = "drop table %s"; |
---|
204 | |
---|
205 | function CreateSequence($seqname='adodbseq',$startID=1) |
---|
206 | { |
---|
207 | if (empty($this->_genSeqSQL)) return false; |
---|
208 | $u = strtoupper($seqname); |
---|
209 | |
---|
210 | $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); |
---|
211 | if (!$ok) return false; |
---|
212 | return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); |
---|
213 | } |
---|
214 | |
---|
215 | function GenID($seqname='adodbseq',$startID=1) |
---|
216 | { |
---|
217 | // post-nuke sets hasGenID to false |
---|
218 | if (!$this->hasGenID) return false; |
---|
219 | |
---|
220 | $getnext = sprintf($this->_genIDSQL,$seqname); |
---|
221 | $holdtransOK = $this->_transOK; // save the current status |
---|
222 | $rs = @$this->Execute($getnext); |
---|
223 | if (!$rs) { |
---|
224 | if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset |
---|
225 | $u = strtoupper($seqname); |
---|
226 | $this->Execute(sprintf($this->_genSeqSQL,$seqname)); |
---|
227 | $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); |
---|
228 | $rs = $this->Execute($getnext); |
---|
229 | } |
---|
230 | $this->genID = mysqli_insert_id($this->_connectionID); |
---|
231 | |
---|
232 | if ($rs) $rs->Close(); |
---|
233 | |
---|
234 | return $this->genID; |
---|
235 | } |
---|
236 | |
---|
237 | function &MetaDatabases() |
---|
238 | { |
---|
239 | $query = "SHOW DATABASES"; |
---|
240 | $ret =& $this->Execute($query); |
---|
241 | return $ret; |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | function &MetaIndexes ($table, $primary = FALSE) |
---|
246 | { |
---|
247 | // save old fetch mode |
---|
248 | global $ADODB_FETCH_MODE; |
---|
249 | |
---|
250 | $save = $ADODB_FETCH_MODE; |
---|
251 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
---|
252 | if ($this->fetchMode !== FALSE) { |
---|
253 | $savem = $this->SetFetchMode(FALSE); |
---|
254 | } |
---|
255 | |
---|
256 | // get index details |
---|
257 | $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table)); |
---|
258 | |
---|
259 | // restore fetchmode |
---|
260 | if (isset($savem)) { |
---|
261 | $this->SetFetchMode($savem); |
---|
262 | } |
---|
263 | $ADODB_FETCH_MODE = $save; |
---|
264 | |
---|
265 | if (!is_object($rs)) { |
---|
266 | return FALSE; |
---|
267 | } |
---|
268 | |
---|
269 | $indexes = array (); |
---|
270 | |
---|
271 | // parse index data into array |
---|
272 | while ($row = $rs->FetchRow()) { |
---|
273 | if ($primary == FALSE AND $row[2] == 'PRIMARY') { |
---|
274 | continue; |
---|
275 | } |
---|
276 | |
---|
277 | if (!isset($indexes[$row[2]])) { |
---|
278 | $indexes[$row[2]] = array( |
---|
279 | 'unique' => ($row[1] == 0), |
---|
280 | 'columns' => array() |
---|
281 | ); |
---|
282 | } |
---|
283 | |
---|
284 | $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4]; |
---|
285 | } |
---|
286 | |
---|
287 | // sort columns by order in the index |
---|
288 | foreach ( array_keys ($indexes) as $index ) |
---|
289 | { |
---|
290 | ksort ($indexes[$index]['columns']); |
---|
291 | } |
---|
292 | |
---|
293 | return $indexes; |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | // Format date column in sql string given an input format that understands Y M D |
---|
298 | function SQLDate($fmt, $col=false) |
---|
299 | { |
---|
300 | if (!$col) $col = $this->sysTimeStamp; |
---|
301 | $s = 'DATE_FORMAT('.$col.",'"; |
---|
302 | $concat = false; |
---|
303 | $len = strlen($fmt); |
---|
304 | for ($i=0; $i < $len; $i++) { |
---|
305 | $ch = $fmt[$i]; |
---|
306 | switch($ch) { |
---|
307 | case 'Y': |
---|
308 | case 'y': |
---|
309 | $s .= '%Y'; |
---|
310 | break; |
---|
311 | case 'Q': |
---|
312 | case 'q': |
---|
313 | $s .= "'),Quarter($col)"; |
---|
314 | |
---|
315 | if ($len > $i+1) $s .= ",DATE_FORMAT($col,'"; |
---|
316 | else $s .= ",('"; |
---|
317 | $concat = true; |
---|
318 | break; |
---|
319 | case 'M': |
---|
320 | $s .= '%b'; |
---|
321 | break; |
---|
322 | |
---|
323 | case 'm': |
---|
324 | $s .= '%m'; |
---|
325 | break; |
---|
326 | case 'D': |
---|
327 | case 'd': |
---|
328 | $s .= '%d'; |
---|
329 | break; |
---|
330 | |
---|
331 | case 'H': |
---|
332 | $s .= '%H'; |
---|
333 | break; |
---|
334 | |
---|
335 | case 'h': |
---|
336 | $s .= '%I'; |
---|
337 | break; |
---|
338 | |
---|
339 | case 'i': |
---|
340 | $s .= '%i'; |
---|
341 | break; |
---|
342 | |
---|
343 | case 's': |
---|
344 | $s .= '%s'; |
---|
345 | break; |
---|
346 | |
---|
347 | case 'a': |
---|
348 | case 'A': |
---|
349 | $s .= '%p'; |
---|
350 | break; |
---|
351 | |
---|
352 | default: |
---|
353 | |
---|
354 | if ($ch == '\\') { |
---|
355 | $i++; |
---|
356 | $ch = substr($fmt,$i,1); |
---|
357 | } |
---|
358 | $s .= $ch; |
---|
359 | break; |
---|
360 | } |
---|
361 | } |
---|
362 | $s.="')"; |
---|
363 | if ($concat) $s = "CONCAT($s)"; |
---|
364 | return $s; |
---|
365 | } |
---|
366 | |
---|
367 | // returns concatenated string |
---|
368 | // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator |
---|
369 | function Concat() |
---|
370 | { |
---|
371 | $s = ""; |
---|
372 | $arr = func_get_args(); |
---|
373 | |
---|
374 | // suggestion by andrew005@mnogo.ru |
---|
375 | $s = implode(',',$arr); |
---|
376 | if (strlen($s) > 0) return "CONCAT($s)"; |
---|
377 | else return ''; |
---|
378 | } |
---|
379 | |
---|
380 | // dayFraction is a day in floating point |
---|
381 | function OffsetDate($dayFraction,$date=false) |
---|
382 | { |
---|
383 | if (!$date) |
---|
384 | $date = $this->sysDate; |
---|
385 | return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)"; |
---|
386 | } |
---|
387 | |
---|
388 | |
---|
389 | function &MetaColumns($table) |
---|
390 | { |
---|
391 | if ($this->metaColumnsSQL) { |
---|
392 | global $ADODB_FETCH_MODE; |
---|
393 | $save = $ADODB_FETCH_MODE; |
---|
394 | $rs = false; |
---|
395 | switch($ADODB_FETCH_MODE) |
---|
396 | { |
---|
397 | case ADODB_FETCH_NUM: |
---|
398 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
---|
399 | $rs = $this->Execute(sprintf($this->metaColumnsSQL, |
---|
400 | $table)); |
---|
401 | |
---|
402 | $ADODB_FETCH_MODE = $save; |
---|
403 | if ($rs === false) break; |
---|
404 | $retarr = array(); |
---|
405 | while (!$rs->EOF){ |
---|
406 | $fld = new ADOFieldObject(); |
---|
407 | $fld->name = $rs->fields[0]; |
---|
408 | $fld->type = $rs->fields[1]; |
---|
409 | // split type into type(length): |
---|
410 | if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) |
---|
411 | { |
---|
412 | $fld->type = $query_array[1]; |
---|
413 | $fld->max_length = $query_array[2]; |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | $fld->max_length = -1; |
---|
418 | } |
---|
419 | $fld->not_null = ($rs->fields[2] != 'YES'); |
---|
420 | $fld->primary_key = ($rs->fields[3] == 'PRI'); |
---|
421 | $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); |
---|
422 | $fld->binary = (strpos($fld->type,'blob') !== false); |
---|
423 | if (!$fld->binary) |
---|
424 | { |
---|
425 | $d = $rs->fields[4]; |
---|
426 | $d = $rs->fields['Default']; |
---|
427 | if ($d != "" && $d != "NULL") |
---|
428 | { |
---|
429 | $fld->has_default = true; |
---|
430 | $fld->default_value = $d; |
---|
431 | } |
---|
432 | else |
---|
433 | { |
---|
434 | $fld->has_default = false; |
---|
435 | } |
---|
436 | } |
---|
437 | $retarr[strtoupper($fld->name)] = $fld; |
---|
438 | $rs->MoveNext(); |
---|
439 | } |
---|
440 | break; |
---|
441 | case ADODB_FETCH_ASSOC: |
---|
442 | case ADODB_FETCH_DEFAULT: |
---|
443 | case ADODB_FETCH_BOTH: |
---|
444 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
---|
445 | $rs = $this->Execute(sprintf($this->metaColumnsSQL, |
---|
446 | $table)); |
---|
447 | $ADODB_FETCH_MODE = $save; |
---|
448 | if ($rs === false) break; |
---|
449 | $retarr = array(); |
---|
450 | while (!$rs->EOF){ |
---|
451 | $fld = new ADOFieldObject(); |
---|
452 | $fld->name = $rs->fields['Field']; |
---|
453 | $fld->type = $rs->fields['Type']; |
---|
454 | |
---|
455 | // split type into type(length): |
---|
456 | if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) |
---|
457 | { |
---|
458 | $fld->type = $query_array[1]; |
---|
459 | $fld->max_length = $query_array[2]; |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | $fld->max_length = -1; |
---|
464 | } |
---|
465 | $fld->not_null = ($rs->fields['Null'] != 'YES'); |
---|
466 | $fld->primary_key = ($rs->fields['Key'] == 'PRI'); |
---|
467 | $fld->auto_increment = (strpos($rs->fields['Extra'], 'auto_increment') !== false); |
---|
468 | $fld->binary = (strpos($fld->type,'blob') !== false); |
---|
469 | if (!$fld->binary) |
---|
470 | { |
---|
471 | $d = $rs->fields['Default']; |
---|
472 | if ($d != "" && $d != "NULL") |
---|
473 | { |
---|
474 | $fld->has_default = true; |
---|
475 | $fld->default_value = $d; |
---|
476 | } |
---|
477 | else |
---|
478 | { |
---|
479 | $fld->has_default = false; |
---|
480 | } |
---|
481 | } |
---|
482 | $retarr[strtoupper($fld->name)] = $fld; |
---|
483 | $rs->MoveNext(); |
---|
484 | } |
---|
485 | break; |
---|
486 | default: |
---|
487 | } |
---|
488 | |
---|
489 | if ($rs === false) return false; |
---|
490 | $rs->Close(); |
---|
491 | return $retarr; |
---|
492 | } |
---|
493 | return false; |
---|
494 | } |
---|
495 | |
---|
496 | // returns true or false |
---|
497 | function SelectDB($dbName) |
---|
498 | { |
---|
499 | // $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID); |
---|
500 | $this->databaseName = $dbName; |
---|
501 | if ($this->_connectionID) { |
---|
502 | $result = @mysqli_select_db($this->_connectionID, $dbName); |
---|
503 | if (!$result) { |
---|
504 | ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg()); |
---|
505 | } |
---|
506 | return $result; |
---|
507 | } |
---|
508 | return false; |
---|
509 | } |
---|
510 | |
---|
511 | // parameters use PostgreSQL convention, not MySQL |
---|
512 | function &SelectLimit($sql, |
---|
513 | $nrows = -1, |
---|
514 | $offset = -1, |
---|
515 | $inputarr = false, |
---|
516 | $arg3 = false, |
---|
517 | $secs = 0) |
---|
518 | { |
---|
519 | $offsetStr = ($offset >= 0) ? "$offset," : ''; |
---|
520 | |
---|
521 | if ($secs) |
---|
522 | $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); |
---|
523 | else |
---|
524 | $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); |
---|
525 | |
---|
526 | return $rs; |
---|
527 | } |
---|
528 | |
---|
529 | |
---|
530 | function Prepare($sql) |
---|
531 | { |
---|
532 | return $sql; |
---|
533 | |
---|
534 | $stmt = $this->_connectionID->prepare($sql); |
---|
535 | if (!$stmt) { |
---|
536 | echo $this->ErrorMsg(); |
---|
537 | return $sql; |
---|
538 | } |
---|
539 | return array($sql,$stmt); |
---|
540 | } |
---|
541 | |
---|
542 | |
---|
543 | // returns queryID or false |
---|
544 | function _query($sql, $inputarr) |
---|
545 | { |
---|
546 | global $ADODB_COUNTRECS; |
---|
547 | |
---|
548 | if (is_array($sql)) { |
---|
549 | $stmt = $sql[1]; |
---|
550 | $a = ''; |
---|
551 | foreach($inputarr as $k => $v) { |
---|
552 | if (is_string($v)) $a .= 's'; |
---|
553 | else if (is_integer($v)) $a .= 'i'; |
---|
554 | else $a .= 'd'; |
---|
555 | } |
---|
556 | |
---|
557 | $fnarr =& array_merge( array($stmt,$a) , $inputarr); |
---|
558 | $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr); |
---|
559 | |
---|
560 | $ret = mysqli_stmt_execute($stmt); |
---|
561 | return $ret; |
---|
562 | } |
---|
563 | if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) { |
---|
564 | if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); |
---|
565 | return false; |
---|
566 | } |
---|
567 | |
---|
568 | return $mysql_res; |
---|
569 | } |
---|
570 | |
---|
571 | /* Returns: the last error message from previous database operation */ |
---|
572 | function ErrorMsg() |
---|
573 | { |
---|
574 | if (empty($this->_connectionID)) |
---|
575 | $this->_errorMsg = @mysqli_error(); |
---|
576 | else |
---|
577 | $this->_errorMsg = @mysqli_error($this->_connectionID); |
---|
578 | return $this->_errorMsg; |
---|
579 | } |
---|
580 | |
---|
581 | /* Returns: the last error number from previous database operation */ |
---|
582 | function ErrorNo() |
---|
583 | { |
---|
584 | if (empty($this->_connectionID)) |
---|
585 | return @mysqli_errno(); |
---|
586 | else |
---|
587 | return @mysqli_errno($this->_connectionID); |
---|
588 | } |
---|
589 | |
---|
590 | // returns true or false |
---|
591 | function _close() |
---|
592 | { |
---|
593 | @mysqli_close($this->_connectionID); |
---|
594 | $this->_connectionID = false; |
---|
595 | } |
---|
596 | |
---|
597 | /* |
---|
598 | * Maximum size of C field |
---|
599 | */ |
---|
600 | function CharMax() |
---|
601 | { |
---|
602 | return 255; |
---|
603 | } |
---|
604 | |
---|
605 | /* |
---|
606 | * Maximum size of X field |
---|
607 | */ |
---|
608 | function TextMax() |
---|
609 | { |
---|
610 | return 4294967295; |
---|
611 | } |
---|
612 | |
---|
613 | |
---|
614 | } |
---|
615 | |
---|
616 | /*-------------------------------------------------------------------------------------- |
---|
617 | Class Name: Recordset |
---|
618 | --------------------------------------------------------------------------------------*/ |
---|
619 | |
---|
620 | class ADORecordSet_mysqli extends ADORecordSet{ |
---|
621 | |
---|
622 | var $databaseType = "mysqli"; |
---|
623 | var $canSeek = true; |
---|
624 | |
---|
625 | function ADORecordSet_mysqli($queryID, $mode = false) |
---|
626 | { |
---|
627 | if ($mode === false) |
---|
628 | { |
---|
629 | global $ADODB_FETCH_MODE; |
---|
630 | $mode = $ADODB_FETCH_MODE; |
---|
631 | } |
---|
632 | |
---|
633 | switch ($mode) |
---|
634 | { |
---|
635 | case ADODB_FETCH_NUM: |
---|
636 | $this->fetchMode = MYSQLI_NUM; |
---|
637 | break; |
---|
638 | case ADODB_FETCH_ASSOC: |
---|
639 | $this->fetchMode = MYSQLI_ASSOC; |
---|
640 | break; |
---|
641 | case ADODB_FETCH_DEFAULT: |
---|
642 | case ADODB_FETCH_BOTH: |
---|
643 | default: |
---|
644 | $this->fetchMode = MYSQLI_BOTH; |
---|
645 | break; |
---|
646 | } |
---|
647 | |
---|
648 | $this->ADORecordSet($queryID); |
---|
649 | } |
---|
650 | |
---|
651 | function _initrs() |
---|
652 | { |
---|
653 | global $ADODB_COUNTRECS; |
---|
654 | |
---|
655 | $this->_numOfRows = $ADODB_COUNTRECS ? @mysqli_num_rows($this->_queryID) : -1; |
---|
656 | $this->_numOfFields = @mysqli_num_fields($this->_queryID); |
---|
657 | } |
---|
658 | |
---|
659 | function &FetchField($fieldOffset = -1) |
---|
660 | { |
---|
661 | $fieldnr = $fieldOffset; |
---|
662 | if ($fieldOffset != -1) { |
---|
663 | $fieldOffset = mysqli_field_seek($this->_queryID, $fieldnr); |
---|
664 | } |
---|
665 | $o = mysqli_fetch_field($this->_queryID); |
---|
666 | return $o; |
---|
667 | } |
---|
668 | |
---|
669 | function &GetRowAssoc($upper = true) |
---|
670 | { |
---|
671 | if ($this->fetchMode == MYSQLI_ASSOC && !$upper) |
---|
672 | return $this->fields; |
---|
673 | $row =& ADORecordSet::GetRowAssoc($upper); |
---|
674 | return $row; |
---|
675 | } |
---|
676 | |
---|
677 | /* Use associative array to get fields array */ |
---|
678 | function Fields($colname) |
---|
679 | { |
---|
680 | if ($this->fetchMode != MYSQLI_NUM) |
---|
681 | return @$this->fields[$colname]; |
---|
682 | |
---|
683 | if (!$this->bind) { |
---|
684 | $this->bind = array(); |
---|
685 | for ($i = 0; $i < $this->_numOfFields; $i++) { |
---|
686 | $o = $this->FetchField($i); |
---|
687 | $this->bind[strtoupper($o->name)] = $i; |
---|
688 | } |
---|
689 | } |
---|
690 | return $this->fields[$this->bind[strtoupper($colname)]]; |
---|
691 | } |
---|
692 | |
---|
693 | function _seek($row) |
---|
694 | { |
---|
695 | if ($this->_numOfRows == 0) |
---|
696 | return false; |
---|
697 | |
---|
698 | if ($row < 0) |
---|
699 | return false; |
---|
700 | |
---|
701 | mysqli_data_seek($this->_queryID, $row); |
---|
702 | $this->EOF = false; |
---|
703 | return true; |
---|
704 | } |
---|
705 | |
---|
706 | // 10% speedup to move MoveNext to child class |
---|
707 | // This is the only implementation that works now (23-10-2003). |
---|
708 | // Other functions return no or the wrong results. |
---|
709 | function MoveNext() |
---|
710 | { |
---|
711 | if ($this->EOF) return false; |
---|
712 | $this->_currentRow++; |
---|
713 | $this->fields = mysqli_fetch_array($this->_queryID,$this->fetchMode); |
---|
714 | |
---|
715 | if (is_array($this->fields)) return true; |
---|
716 | $this->EOF = true; |
---|
717 | return false; |
---|
718 | } |
---|
719 | |
---|
720 | function _fetch() |
---|
721 | { |
---|
722 | $this->fields = mysqli_fetch_array($this->_queryID,$this->fetchMode); |
---|
723 | return is_array($this->fields); |
---|
724 | } |
---|
725 | |
---|
726 | function _close() |
---|
727 | { |
---|
728 | mysqli_free_result($this->_queryID); |
---|
729 | $this->_queryID = false; |
---|
730 | } |
---|
731 | |
---|
732 | function MetaType($t, $len = -1, $fieldobj = false) |
---|
733 | { |
---|
734 | if (is_object($t)) |
---|
735 | { |
---|
736 | $fieldobj = $t; |
---|
737 | $t = $fieldobj->type; |
---|
738 | $len = $fieldobj->max_length; |
---|
739 | } |
---|
740 | |
---|
741 | $len = -1; // mysql max_length is not accurate |
---|
742 | switch (strtoupper($t)) { |
---|
743 | case 'STRING': |
---|
744 | case 'CHAR': |
---|
745 | case 'VARCHAR': |
---|
746 | case 'TINYBLOB': |
---|
747 | case 'TINYTEXT': |
---|
748 | case 'ENUM': |
---|
749 | case 'SET': |
---|
750 | if ($len <= $this->blobSize) return 'C'; |
---|
751 | |
---|
752 | case 'TEXT': |
---|
753 | case 'LONGTEXT': |
---|
754 | case 'MEDIUMTEXT': |
---|
755 | return 'X'; |
---|
756 | |
---|
757 | // php_mysql extension always returns 'blob' even if 'text' |
---|
758 | // so we have to check whether binary... |
---|
759 | case 'IMAGE': |
---|
760 | case 'LONGBLOB': |
---|
761 | case 'BLOB': |
---|
762 | case 'MEDIUMBLOB': |
---|
763 | return !empty($fieldobj->binary) ? 'B' : 'X'; |
---|
764 | case 'YEAR': |
---|
765 | case 'DATE': |
---|
766 | return 'D'; |
---|
767 | |
---|
768 | case 'TIME': |
---|
769 | case 'DATETIME': |
---|
770 | case 'TIMESTAMP': return 'T'; |
---|
771 | |
---|
772 | case 'INT': |
---|
773 | case 'INTEGER': |
---|
774 | case 'BIGINT': |
---|
775 | case 'TINYINT': |
---|
776 | case 'MEDIUMINT': |
---|
777 | case 'SMALLINT': |
---|
778 | |
---|
779 | if (!empty($fieldobj->primary_key)) return 'R'; |
---|
780 | else return 'I'; |
---|
781 | // Added floating-point types |
---|
782 | // Maybe not necessery. |
---|
783 | case 'FLOAT': |
---|
784 | case 'DOUBLE': |
---|
785 | // case 'DOUBLE PRECISION': |
---|
786 | case 'DECIMAL': |
---|
787 | case 'DEC': |
---|
788 | case 'FIXED': |
---|
789 | default: |
---|
790 | return 'N'; |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | |
---|
795 | } |
---|
796 | |
---|
797 | } |
---|
798 | |
---|
799 | ?> |
---|