Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. 00007 Set tabs to 8. 00008 00009 MySQL code that does not support transactions. Use mysqlt if you need transactions. 00010 Requires mysql client. Works on Windows and Unix. 00011 00012 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com) 00013 */ 00014 00015 // security - hide paths 00016 if (!defined('ADODB_DIR')) die(); 00017 00018 if (! defined("_ADODB_MYSQL_LAYER")) { 00019 define("_ADODB_MYSQL_LAYER", 1 ); 00020 00021 class ADODB_mysql extends ADOConnection { 00022 var $databaseType = 'mysql'; 00023 var $dataProvider = 'mysql'; 00024 var $hasInsertID = true; 00025 var $hasAffectedRows = true; 00026 var $metaTablesSQL = "SHOW TABLES"; 00027 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`"; 00028 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 00029 var $hasLimit = true; 00030 var $hasMoveFirst = true; 00031 var $hasGenID = true; 00032 var $isoDates = true; // accepts dates in ISO format 00033 var $sysDate = 'CURDATE()'; 00034 var $sysTimeStamp = 'NOW()'; 00035 var $hasTransactions = false; 00036 var $forceNewConnect = false; 00037 var $poorAffectedRows = true; 00038 var $clientFlags = 0; 00039 var $substr = "substring"; 00040 var $nameQuote = '`'; 00041 var $compat323 = false; // true if compat with mysql 3.23 00042 00043 function ADODB_mysql() 00044 { 00045 if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_'; 00046 } 00047 00048 function ServerInfo() 00049 { 00050 $arr['description'] = ADOConnection::GetOne("select version()"); 00051 $arr['version'] = ADOConnection::_findvers($arr['description']); 00052 return $arr; 00053 } 00054 00055 function IfNull( $field, $ifNull ) 00056 { 00057 return " IFNULL($field, $ifNull) "; // if MySQL 00058 } 00059 00060 00061 function &MetaTables($ttype=false,$showSchema=false,$mask=false) 00062 { 00063 $save = $this->metaTablesSQL; 00064 if ($showSchema && is_string($showSchema)) { 00065 $this->metaTablesSQL .= " from $showSchema"; 00066 } 00067 00068 if ($mask) { 00069 $mask = $this->qstr($mask); 00070 $this->metaTablesSQL .= " like $mask"; 00071 } 00072 $ret =& ADOConnection::MetaTables($ttype,$showSchema); 00073 00074 $this->metaTablesSQL = $save; 00075 return $ret; 00076 } 00077 00078 00079 function &MetaIndexes ($table, $primary = FALSE, $owner=false) 00080 { 00081 // save old fetch mode 00082 global $ADODB_FETCH_MODE; 00083 00084 $false = false; 00085 $save = $ADODB_FETCH_MODE; 00086 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00087 if ($this->fetchMode !== FALSE) { 00088 $savem = $this->SetFetchMode(FALSE); 00089 } 00090 00091 // get index details 00092 $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table)); 00093 00094 // restore fetchmode 00095 if (isset($savem)) { 00096 $this->SetFetchMode($savem); 00097 } 00098 $ADODB_FETCH_MODE = $save; 00099 00100 if (!is_object($rs)) { 00101 return $false; 00102 } 00103 00104 $indexes = array (); 00105 00106 // parse index data into array 00107 while ($row = $rs->FetchRow()) { 00108 if ($primary == FALSE AND $row[2] == 'PRIMARY') { 00109 continue; 00110 } 00111 00112 if (!isset($indexes[$row[2]])) { 00113 $indexes[$row[2]] = array( 00114 'unique' => ($row[1] == 0), 00115 'columns' => array() 00116 ); 00117 } 00118 00119 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4]; 00120 } 00121 00122 // sort columns by order in the index 00123 foreach ( array_keys ($indexes) as $index ) 00124 { 00125 ksort ($indexes[$index]['columns']); 00126 } 00127 00128 return $indexes; 00129 } 00130 00131 00132 // if magic quotes disabled, use mysql_real_escape_string() 00133 function qstr($s,$magic_quotes=false) 00134 { 00135 if (!$magic_quotes) { 00136 00137 if (ADODB_PHPVER >= 0x4300) { 00138 if (is_resource($this->_connectionID)) 00139 return "'".mysql_real_escape_string($s,$this->_connectionID)."'"; 00140 } 00141 if ($this->replaceQuote[0] == '\\'){ 00142 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); 00143 } 00144 return "'".str_replace("'",$this->replaceQuote,$s)."'"; 00145 } 00146 00147 // undo magic quotes for " 00148 $s = str_replace('\\"','"',$s); 00149 return "'$s'"; 00150 } 00151 00152 function _insertid() 00153 { 00154 return ADOConnection::GetOne('SELECT LAST_INSERT_ID()'); 00155 //return mysql_insert_id($this->_connectionID); 00156 } 00157 00158 function GetOne($sql,$inputarr=false) 00159 { 00160 if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) { 00161 $rs =& $this->SelectLimit($sql,1,-1,$inputarr); 00162 if ($rs) { 00163 $rs->Close(); 00164 if ($rs->EOF) return false; 00165 return reset($rs->fields); 00166 } 00167 } else { 00168 return ADOConnection::GetOne($sql,$inputarr); 00169 } 00170 return false; 00171 } 00172 00173 function BeginTrans() 00174 { 00175 if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver"); 00176 } 00177 00178 function _affectedrows() 00179 { 00180 return mysql_affected_rows($this->_connectionID); 00181 } 00182 00183 // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html 00184 // Reference on Last_Insert_ID on the recommended way to simulate sequences 00185 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; 00186 var $_genSeqSQL = "create table %s (id int not null)"; 00187 var $_genSeq2SQL = "insert into %s values (%s)"; 00188 var $_dropSeqSQL = "drop table %s"; 00189 00190 function CreateSequence($seqname='adodbseq',$startID=1) 00191 { 00192 if (empty($this->_genSeqSQL)) return false; 00193 $u = strtoupper($seqname); 00194 00195 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 00196 if (!$ok) return false; 00197 return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); 00198 } 00199 00200 00201 function GenID($seqname='adodbseq',$startID=1) 00202 { 00203 // post-nuke sets hasGenID to false 00204 if (!$this->hasGenID) return false; 00205 00206 $savelog = $this->_logsql; 00207 $this->_logsql = false; 00208 $getnext = sprintf($this->_genIDSQL,$seqname); 00209 $holdtransOK = $this->_transOK; // save the current status 00210 $rs = @$this->Execute($getnext); 00211 if (!$rs) { 00212 if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset 00213 $u = strtoupper($seqname); 00214 $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 00215 $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); 00216 $rs = $this->Execute($getnext); 00217 } 00218 $this->genID = mysql_insert_id($this->_connectionID); 00219 00220 if ($rs) $rs->Close(); 00221 00222 $this->_logsql = $savelog; 00223 return $this->genID; 00224 } 00225 00226 function &MetaDatabases() 00227 { 00228 $qid = mysql_list_dbs($this->_connectionID); 00229 $arr = array(); 00230 $i = 0; 00231 $max = mysql_num_rows($qid); 00232 while ($i < $max) { 00233 $db = mysql_tablename($qid,$i); 00234 if ($db != 'mysql') $arr[] = $db; 00235 $i += 1; 00236 } 00237 return $arr; 00238 } 00239 00240 00241 // Format date column in sql string given an input format that understands Y M D 00242 function SQLDate($fmt, $col=false) 00243 { 00244 if (!$col) $col = $this->sysTimeStamp; 00245 $s = 'DATE_FORMAT('.$col.",'"; 00246 $concat = false; 00247 $len = strlen($fmt); 00248 for ($i=0; $i < $len; $i++) { 00249 $ch = $fmt[$i]; 00250 switch($ch) { 00251 00252 default: 00253 if ($ch == '\\') { 00254 $i++; 00255 $ch = substr($fmt,$i,1); 00256 } 00258 case '-': 00259 case '/': 00260 $s .= $ch; 00261 break; 00262 00263 case 'Y': 00264 case 'y': 00265 $s .= '%Y'; 00266 break; 00267 case 'M': 00268 $s .= '%b'; 00269 break; 00270 00271 case 'm': 00272 $s .= '%m'; 00273 break; 00274 case 'D': 00275 case 'd': 00276 $s .= '%d'; 00277 break; 00278 00279 case 'Q': 00280 case 'q': 00281 $s .= "'),Quarter($col)"; 00282 00283 if ($len > $i+1) $s .= ",DATE_FORMAT($col,'"; 00284 else $s .= ",('"; 00285 $concat = true; 00286 break; 00287 00288 case 'H': 00289 $s .= '%H'; 00290 break; 00291 00292 case 'h': 00293 $s .= '%I'; 00294 break; 00295 00296 case 'i': 00297 $s .= '%i'; 00298 break; 00299 00300 case 's': 00301 $s .= '%s'; 00302 break; 00303 00304 case 'a': 00305 case 'A': 00306 $s .= '%p'; 00307 break; 00308 00309 case 'w': 00310 $s .= '%w'; 00311 break; 00312 00313 case 'W': 00314 $s .= '%U'; 00315 break; 00316 00317 case 'l': 00318 $s .= '%W'; 00319 break; 00320 } 00321 } 00322 $s.="')"; 00323 if ($concat) $s = "CONCAT($s)"; 00324 return $s; 00325 } 00326 00327 00328 // returns concatenated string 00329 // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator 00330 function Concat() 00331 { 00332 $s = ""; 00333 $arr = func_get_args(); 00334 00335 // suggestion by andrew005@mnogo.ru 00336 $s = implode(',',$arr); 00337 if (strlen($s) > 0) return "CONCAT($s)"; 00338 else return ''; 00339 } 00340 00341 function OffsetDate($dayFraction,$date=false) 00342 { 00343 if (!$date) $date = $this->sysDate; 00344 00345 $fraction = $dayFraction * 24 * 3600; 00346 return $date . ' + INTERVAL ' . $fraction.' SECOND'; 00347 00348 // return "from_unixtime(unix_timestamp($date)+$fraction)"; 00349 } 00350 00351 // returns true or false 00352 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) 00353 { 00354 if (!empty($this->port)) $argHostname .= ":".$this->port; 00355 00356 if (ADODB_PHPVER >= 0x4300) 00357 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, 00358 $this->forceNewConnect,$this->clientFlags); 00359 else if (ADODB_PHPVER >= 0x4200) 00360 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, 00361 $this->forceNewConnect); 00362 else 00363 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword); 00364 00365 if ($this->_connectionID === false) return false; 00366 if ($argDatabasename) return $this->SelectDB($argDatabasename); 00367 return true; 00368 } 00369 00370 // returns true or false 00371 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 00372 { 00373 if (!empty($this->port)) $argHostname .= ":".$this->port; 00374 00375 if (ADODB_PHPVER >= 0x4300) 00376 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags); 00377 else 00378 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword); 00379 if ($this->_connectionID === false) return false; 00380 if ($this->autoRollback) $this->RollbackTrans(); 00381 if ($argDatabasename) return $this->SelectDB($argDatabasename); 00382 return true; 00383 } 00384 00385 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 00386 { 00387 $this->forceNewConnect = true; 00388 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); 00389 } 00390 00391 function &MetaColumns($table) 00392 { 00393 $this->_findschema($table,$schema); 00394 if ($schema) { 00395 $dbName = $this->database; 00396 $this->SelectDB($schema); 00397 } 00398 global $ADODB_FETCH_MODE; 00399 $save = $ADODB_FETCH_MODE; 00400 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00401 00402 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 00403 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); 00404 00405 if ($schema) { 00406 $this->SelectDB($dbName); 00407 } 00408 00409 if (isset($savem)) $this->SetFetchMode($savem); 00410 $ADODB_FETCH_MODE = $save; 00411 if (!is_object($rs)) { 00412 $false = false; 00413 return $false; 00414 } 00415 00416 $retarr = array(); 00417 while (!$rs->EOF){ 00418 $fld = new ADOFieldObject(); 00419 $fld->name = $rs->fields[0]; 00420 $type = $rs->fields[1]; 00421 00422 // split type into type(length): 00423 $fld->scale = null; 00424 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { 00425 $fld->type = $query_array[1]; 00426 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 00427 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1; 00428 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) { 00429 $fld->type = $query_array[1]; 00430 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 00431 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { 00432 $fld->type = $query_array[1]; 00433 $arr = explode(",",$query_array[2]); 00434 $fld->enums = $arr; 00435 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 00436 $fld->max_length = ($zlen > 0) ? $zlen : 1; 00437 } else { 00438 $fld->type = $type; 00439 $fld->max_length = -1; 00440 } 00441 $fld->not_null = ($rs->fields[2] != 'YES'); 00442 $fld->primary_key = ($rs->fields[3] == 'PRI'); 00443 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); 00444 $fld->binary = (strpos($type,'blob') !== false); 00445 $fld->unsigned = (strpos($type,'unsigned') !== false); 00446 00447 if (!$fld->binary) { 00448 $d = $rs->fields[4]; 00449 if ($d != '' && $d != 'NULL') { 00450 $fld->has_default = true; 00451 $fld->default_value = $d; 00452 } else { 00453 $fld->has_default = false; 00454 } 00455 } 00456 00457 if ($save == ADODB_FETCH_NUM) { 00458 $retarr[] = $fld; 00459 } else { 00460 $retarr[strtoupper($fld->name)] = $fld; 00461 } 00462 $rs->MoveNext(); 00463 } 00464 00465 $rs->Close(); 00466 return $retarr; 00467 } 00468 00469 // returns true or false 00470 function SelectDB($dbName) 00471 { 00472 $this->database = $dbName; 00473 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 00474 if ($this->_connectionID) { 00475 return @mysql_select_db($dbName,$this->_connectionID); 00476 } 00477 else return false; 00478 } 00479 00480 // parameters use PostgreSQL convention, not MySQL 00481 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0) 00482 { 00483 $offsetStr =($offset>=0) ? ((integer)$offset)."," : ''; 00484 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220 00485 if ($nrows < 0) $nrows = '18446744073709551615'; 00486 00487 if ($secs) 00488 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr); 00489 else 00490 $rs =& $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr); 00491 return $rs; 00492 } 00493 00494 // returns queryID or false 00495 function _query($sql,$inputarr) 00496 { 00497 //global $ADODB_COUNTRECS; 00498 //if($ADODB_COUNTRECS) 00499 return mysql_query($sql,$this->_connectionID); 00500 //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6 00501 } 00502 00503 /* Returns: the last error message from previous database operation */ 00504 function ErrorMsg() 00505 { 00506 00507 if ($this->_logsql) return $this->_errorMsg; 00508 if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error(); 00509 else $this->_errorMsg = @mysql_error($this->_connectionID); 00510 return $this->_errorMsg; 00511 } 00512 00513 /* Returns: the last error number from previous database operation */ 00514 function ErrorNo() 00515 { 00516 if ($this->_logsql) return $this->_errorCode; 00517 if (empty($this->_connectionID)) return @mysql_errno(); 00518 else return @mysql_errno($this->_connectionID); 00519 } 00520 00521 // returns true or false 00522 function _close() 00523 { 00524 @mysql_close($this->_connectionID); 00525 $this->_connectionID = false; 00526 } 00527 00528 00529 /* 00530 * Maximum size of C field 00531 */ 00532 function CharMax() 00533 { 00534 return 255; 00535 } 00536 00537 /* 00538 * Maximum size of X field 00539 */ 00540 function TextMax() 00541 { 00542 return 4294967295; 00543 } 00544 00545 // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx> 00546 function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) 00547 { 00548 global $ADODB_FETCH_MODE; 00549 if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true; 00550 00551 if ( !empty($owner) ) { 00552 $table = "$owner.$table"; 00553 } 00554 $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table)); 00555 if ($associative) $create_sql = $a_create_table["Create Table"]; 00556 else $create_sql = $a_create_table[1]; 00557 00558 $matches = array(); 00559 00560 if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false; 00561 $foreign_keys = array(); 00562 $num_keys = count($matches[0]); 00563 for ( $i = 0; $i < $num_keys; $i ++ ) { 00564 $my_field = explode('`, `', $matches[1][$i]); 00565 $ref_table = $matches[2][$i]; 00566 $ref_field = explode('`, `', $matches[3][$i]); 00567 00568 if ( $upper ) { 00569 $ref_table = strtoupper($ref_table); 00570 } 00571 00572 $foreign_keys[$ref_table] = array(); 00573 $num_fields = count($my_field); 00574 for ( $j = 0; $j < $num_fields; $j ++ ) { 00575 if ( $associative ) { 00576 $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j]; 00577 } else { 00578 $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}"; 00579 } 00580 } 00581 } 00582 00583 return $foreign_keys; 00584 } 00585 00586 00587 } 00588 00589 /*-------------------------------------------------------------------------------------- 00590 Class Name: Recordset 00591 --------------------------------------------------------------------------------------*/ 00592 00593 00594 class ADORecordSet_mysql extends ADORecordSet{ 00595 00596 var $databaseType = "mysql"; 00597 var $canSeek = true; 00598 00599 function ADORecordSet_mysql($queryID,$mode=false) 00600 { 00601 if ($mode === false) { 00602 global $ADODB_FETCH_MODE; 00603 $mode = $ADODB_FETCH_MODE; 00604 } 00605 switch ($mode) 00606 { 00607 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 00608 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 00609 case ADODB_FETCH_DEFAULT: 00610 case ADODB_FETCH_BOTH: 00611 default: 00612 $this->fetchMode = MYSQL_BOTH; break; 00613 } 00614 $this->adodbFetchMode = $mode; 00615 $this->ADORecordSet($queryID); 00616 } 00617 00618 function _initrs() 00619 { 00620 //GLOBAL $ADODB_COUNTRECS; 00621 // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1; 00622 $this->_numOfRows = @mysql_num_rows($this->_queryID); 00623 $this->_numOfFields = @mysql_num_fields($this->_queryID); 00624 } 00625 00626 function &FetchField($fieldOffset = -1) 00627 { 00628 if ($fieldOffset != -1) { 00629 $o = @mysql_fetch_field($this->_queryID, $fieldOffset); 00630 $f = @mysql_field_flags($this->_queryID,$fieldOffset); 00631 $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com) 00632 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable 00633 $o->binary = (strpos($f,'binary')!== false); 00634 } 00635 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ 00636 $o = @mysql_fetch_field($this->_queryID); 00637 $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com) 00638 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable 00639 } 00640 00641 return $o; 00642 } 00643 00644 function &GetRowAssoc($upper=true) 00645 { 00646 if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields; 00647 else $row =& ADORecordSet::GetRowAssoc($upper); 00648 return $row; 00649 } 00650 00651 /* Use associative array to get fields array */ 00652 function Fields($colname) 00653 { 00654 // added @ by "Michael William Miller" <mille562@pilot.msu.edu> 00655 if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname]; 00656 00657 if (!$this->bind) { 00658 $this->bind = array(); 00659 for ($i=0; $i < $this->_numOfFields; $i++) { 00660 $o = $this->FetchField($i); 00661 $this->bind[strtoupper($o->name)] = $i; 00662 } 00663 } 00664 return $this->fields[$this->bind[strtoupper($colname)]]; 00665 } 00666 00667 function _seek($row) 00668 { 00669 if ($this->_numOfRows == 0) return false; 00670 return @mysql_data_seek($this->_queryID,$row); 00671 } 00672 00673 function MoveNext() 00674 { 00675 //return adodb_movenext($this); 00676 //if (defined('ADODB_EXTENSION')) return adodb_movenext($this); 00677 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) { 00678 $this->_currentRow += 1; 00679 return true; 00680 } 00681 if (!$this->EOF) { 00682 $this->_currentRow += 1; 00683 $this->EOF = true; 00684 } 00685 return false; 00686 } 00687 00688 function _fetch() 00689 { 00690 $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode); 00691 return is_array($this->fields); 00692 } 00693 00694 function _close() { 00695 @mysql_free_result($this->_queryID); 00696 $this->_queryID = false; 00697 } 00698 00699 function MetaType($t,$len=-1,$fieldobj=false) 00700 { 00701 if (is_object($t)) { 00702 $fieldobj = $t; 00703 $t = $fieldobj->type; 00704 $len = $fieldobj->max_length; 00705 } 00706 00707 $len = -1; // mysql max_length is not accurate 00708 switch (strtoupper($t)) { 00709 case 'STRING': 00710 case 'CHAR': 00711 case 'VARCHAR': 00712 case 'TINYBLOB': 00713 case 'TINYTEXT': 00714 case 'ENUM': 00715 case 'SET': 00716 if ($len <= $this->blobSize) return 'C'; 00717 00718 case 'TEXT': 00719 case 'LONGTEXT': 00720 case 'MEDIUMTEXT': 00721 return 'X'; 00722 00723 // php_mysql extension always returns 'blob' even if 'text' 00724 // so we have to check whether binary... 00725 case 'IMAGE': 00726 case 'LONGBLOB': 00727 case 'BLOB': 00728 case 'MEDIUMBLOB': 00729 return !empty($fieldobj->binary) ? 'B' : 'X'; 00730 00731 case 'YEAR': 00732 case 'DATE': return 'D'; 00733 00734 case 'TIME': 00735 case 'DATETIME': 00736 case 'TIMESTAMP': return 'T'; 00737 00738 case 'INT': 00739 case 'INTEGER': 00740 case 'BIGINT': 00741 case 'TINYINT': 00742 case 'MEDIUMINT': 00743 case 'SMALLINT': 00744 00745 if (!empty($fieldobj->primary_key)) return 'R'; 00746 else return 'I'; 00747 00748 default: return 'N'; 00749 } 00750 } 00751 00752 } 00753 00754 class ADORecordSet_ext_mysql extends ADORecordSet_mysql { 00755 function ADORecordSet_ext_mysql($queryID,$mode=false) 00756 { 00757 if ($mode === false) { 00758 global $ADODB_FETCH_MODE; 00759 $mode = $ADODB_FETCH_MODE; 00760 } 00761 switch ($mode) 00762 { 00763 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 00764 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 00765 case ADODB_FETCH_DEFAULT: 00766 case ADODB_FETCH_BOTH: 00767 default: 00768 $this->fetchMode = MYSQL_BOTH; break; 00769 } 00770 $this->adodbFetchMode = $mode; 00771 $this->ADORecordSet($queryID); 00772 } 00773 00774 function MoveNext() 00775 { 00776 return @adodb_movenext($this); 00777 } 00778 } 00779 00780 00781 } 00782 ?>