[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /* 3 V4.65 22 July 2005 (c) 2000-2005 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 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com) 13 */ 14 15 // security - hide paths 16 if (!defined('ADODB_DIR')) die(); 17 18 if (! defined("_ADODB_MYSQL_LAYER")) { 19 define("_ADODB_MYSQL_LAYER", 1 ); 20 21 class ADODB_mysql extends ADOConnection { 22 var $databaseType = 'mysql'; 23 var $dataProvider = 'mysql'; 24 var $hasInsertID = true; 25 var $hasAffectedRows = true; 26 var $metaTablesSQL = "SHOW TABLES"; 27 var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; 28 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 29 var $hasLimit = true; 30 var $hasMoveFirst = true; 31 var $hasGenID = true; 32 var $isoDates = true; // accepts dates in ISO format 33 var $sysDate = 'CURDATE()'; 34 var $sysTimeStamp = 'NOW()'; 35 var $hasTransactions = false; 36 var $forceNewConnect = false; 37 var $poorAffectedRows = true; 38 var $clientFlags = 0; 39 var $substr = "substring"; 40 var $nameQuote = '`'; /// string to use to quote identifiers and names 41 42 function ADODB_mysql() 43 { 44 if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_'; 45 } 46 47 function ServerInfo() 48 { 49 $arr['description'] = ADOConnection::GetOne("select version()"); 50 $arr['version'] = ADOConnection::_findvers($arr['description']); 51 return $arr; 52 } 53 54 function IfNull( $field, $ifNull ) 55 { 56 return " IFNULL($field, $ifNull) "; // if MySQL 57 } 58 59 function &MetaTables($ttype=false,$showSchema=false,$mask=false) 60 { 61 $save = $this->metaTablesSQL; 62 if ($showSchema && is_string($showSchema)) { 63 $this->metaTablesSQL .= " from $showSchema"; 64 } 65 66 if ($mask) { 67 $mask = $this->qstr($mask); 68 $this->metaTablesSQL .= " like $mask"; 69 } 70 $ret =& ADOConnection::MetaTables($ttype,$showSchema); 71 72 $this->metaTablesSQL = $save; 73 return $ret; 74 } 75 76 77 function &MetaIndexes ($table, $primary = FALSE, $owner=false) 78 { 79 // save old fetch mode 80 global $ADODB_FETCH_MODE; 81 82 $false = false; 83 $save = $ADODB_FETCH_MODE; 84 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 85 if ($this->fetchMode !== FALSE) { 86 $savem = $this->SetFetchMode(FALSE); 87 } 88 89 // get index details 90 $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table)); 91 92 // restore fetchmode 93 if (isset($savem)) { 94 $this->SetFetchMode($savem); 95 } 96 $ADODB_FETCH_MODE = $save; 97 98 if (!is_object($rs)) { 99 return $false; 100 } 101 102 $indexes = array (); 103 104 // parse index data into array 105 while ($row = $rs->FetchRow()) { 106 if ($primary == FALSE AND $row[2] == 'PRIMARY') { 107 continue; 108 } 109 110 if (!isset($indexes[$row[2]])) { 111 $indexes[$row[2]] = array( 112 'unique' => ($row[1] == 0), 113 'columns' => array() 114 ); 115 } 116 117 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4]; 118 } 119 120 // sort columns by order in the index 121 foreach ( array_keys ($indexes) as $index ) 122 { 123 ksort ($indexes[$index]['columns']); 124 } 125 126 return $indexes; 127 } 128 129 130 // if magic quotes disabled, use mysql_real_escape_string() 131 function qstr($s,$magic_quotes=false) 132 { 133 if (!$magic_quotes) { 134 135 if (ADODB_PHPVER >= 0x4300) { 136 if (is_resource($this->_connectionID)) 137 return "'".mysql_real_escape_string($s,$this->_connectionID)."'"; 138 } 139 if ($this->replaceQuote[0] == '\\'){ 140 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); 141 } 142 return "'".str_replace("'",$this->replaceQuote,$s)."'"; 143 } 144 145 // undo magic quotes for " 146 $s = str_replace('\\"','"',$s); 147 return "'$s'"; 148 } 149 150 function _insertid() 151 { 152 return ADOConnection::GetOne('SELECT LAST_INSERT_ID()'); 153 //return mysql_insert_id($this->_connectionID); 154 } 155 156 function GetOne($sql,$inputarr=false) 157 { 158 if (strncasecmp($sql,'sele',4) == 0) { 159 $rs =& $this->SelectLimit($sql,1,-1,$inputarr); 160 if ($rs) { 161 $rs->Close(); 162 if ($rs->EOF) return false; 163 return reset($rs->fields); 164 } 165 } else { 166 return ADOConnection::GetOne($sql,$inputarr); 167 } 168 return false; 169 } 170 171 function BeginTrans() 172 { 173 if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver"); 174 } 175 176 function _affectedrows() 177 { 178 return mysql_affected_rows($this->_connectionID); 179 } 180 181 // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html 182 // Reference on Last_Insert_ID on the recommended way to simulate sequences 183 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; 184 var $_genSeqSQL = "create table %s (id int not null)"; 185 var $_genSeq2SQL = "insert into %s values (%s)"; 186 var $_dropSeqSQL = "drop table %s"; 187 188 function CreateSequence($seqname='adodbseq',$startID=1) 189 { 190 if (empty($this->_genSeqSQL)) return false; 191 $u = strtoupper($seqname); 192 193 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 194 if (!$ok) return false; 195 return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); 196 } 197 198 199 function GenID($seqname='adodbseq',$startID=1) 200 { 201 // post-nuke sets hasGenID to false 202 if (!$this->hasGenID) return false; 203 204 $savelog = $this->_logsql; 205 $this->_logsql = false; 206 $getnext = sprintf($this->_genIDSQL,$seqname); 207 $holdtransOK = $this->_transOK; // save the current status 208 $rs = @$this->Execute($getnext); 209 if (!$rs) { 210 if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset 211 $u = strtoupper($seqname); 212 $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 213 $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); 214 $rs = $this->Execute($getnext); 215 } 216 $this->genID = mysql_insert_id($this->_connectionID); 217 218 if ($rs) $rs->Close(); 219 220 $this->_logsql = $savelog; 221 return $this->genID; 222 } 223 224 function &MetaDatabases() 225 { 226 $qid = mysql_list_dbs($this->_connectionID); 227 $arr = array(); 228 $i = 0; 229 $max = mysql_num_rows($qid); 230 while ($i < $max) { 231 $db = mysql_tablename($qid,$i); 232 if ($db != 'mysql') $arr[] = $db; 233 $i += 1; 234 } 235 return $arr; 236 } 237 238 239 // Format date column in sql string given an input format that understands Y M D 240 function SQLDate($fmt, $col=false) 241 { 242 if (!$col) $col = $this->sysTimeStamp; 243 $s = 'DATE_FORMAT('.$col.",'"; 244 $concat = false; 245 $len = strlen($fmt); 246 for ($i=0; $i < $len; $i++) { 247 $ch = $fmt[$i]; 248 switch($ch) { 249 250 default: 251 if ($ch == '\\') { 252 $i++; 253 $ch = substr($fmt,$i,1); 254 } 255 /** FALL THROUGH */ 256 case '-': 257 case '/': 258 $s .= $ch; 259 break; 260 261 case 'Y': 262 case 'y': 263 $s .= '%Y'; 264 break; 265 case 'M': 266 $s .= '%b'; 267 break; 268 269 case 'm': 270 $s .= '%m'; 271 break; 272 case 'D': 273 case 'd': 274 $s .= '%d'; 275 break; 276 277 case 'Q': 278 case 'q': 279 $s .= "'),Quarter($col)"; 280 281 if ($len > $i+1) $s .= ",DATE_FORMAT($col,'"; 282 else $s .= ",('"; 283 $concat = true; 284 break; 285 286 case 'H': 287 $s .= '%H'; 288 break; 289 290 case 'h': 291 $s .= '%I'; 292 break; 293 294 case 'i': 295 $s .= '%i'; 296 break; 297 298 case 's': 299 $s .= '%s'; 300 break; 301 302 case 'a': 303 case 'A': 304 $s .= '%p'; 305 break; 306 307 case 'w': 308 $s .= '%w'; 309 break; 310 311 case 'l': 312 $s .= '%W'; 313 break; 314 } 315 } 316 $s.="')"; 317 if ($concat) $s = "CONCAT($s)"; 318 return $s; 319 } 320 321 322 // returns concatenated string 323 // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator 324 function Concat() 325 { 326 $s = ""; 327 $arr = func_get_args(); 328 329 // suggestion by andrew005@mnogo.ru 330 $s = implode(',',$arr); 331 if (strlen($s) > 0) return "CONCAT($s)"; 332 else return ''; 333 } 334 335 function OffsetDate($dayFraction,$date=false) 336 { 337 if (!$date) $date = $this->sysDate; 338 return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)"; 339 } 340 341 // returns true or false 342 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) 343 { 344 if (!empty($this->port)) $argHostname .= ":".$this->port; 345 346 if (ADODB_PHPVER >= 0x4300) 347 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, 348 $this->forceNewConnect,$this->clientFlags); 349 else if (ADODB_PHPVER >= 0x4200) 350 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, 351 $this->forceNewConnect); 352 else 353 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword); 354 355 if ($this->_connectionID === false) return false; 356 if ($argDatabasename) return $this->SelectDB($argDatabasename); 357 return true; 358 } 359 360 // returns true or false 361 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 362 { 363 if (!empty($this->port)) $argHostname .= ":".$this->port; 364 365 if (ADODB_PHPVER >= 0x4300) 366 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags); 367 else 368 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword); 369 if ($this->_connectionID === false) return false; 370 if ($this->autoRollback) $this->RollbackTrans(); 371 if ($argDatabasename) return $this->SelectDB($argDatabasename); 372 return true; 373 } 374 375 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 376 { 377 $this->forceNewConnect = true; 378 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); 379 } 380 381 function &MetaColumns($table) 382 { 383 $this->_findschema($table,$schema); 384 if ($schema) { 385 $dbName = $this->database; 386 $this->SelectDB($schema); 387 } 388 global $ADODB_FETCH_MODE; 389 $save = $ADODB_FETCH_MODE; 390 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 391 392 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 393 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); 394 395 if ($schema) { 396 $this->SelectDB($dbName); 397 } 398 399 if (isset($savem)) $this->SetFetchMode($savem); 400 $ADODB_FETCH_MODE = $save; 401 if (!is_object($rs)) { 402 $false = false; 403 return $false; 404 } 405 406 $retarr = array(); 407 while (!$rs->EOF){ 408 $fld = new ADOFieldObject(); 409 $fld->name = $rs->fields[0]; 410 $type = $rs->fields[1]; 411 412 // split type into type(length): 413 $fld->scale = null; 414 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { 415 $fld->type = $query_array[1]; 416 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 417 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1; 418 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) { 419 $fld->type = $query_array[1]; 420 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 421 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { 422 $fld->type = $query_array[1]; 423 $arr = explode(",",$query_array[2]); 424 $fld->enums = $arr; 425 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 426 $fld->max_length = ($zlen > 0) ? $zlen : 1; 427 } else { 428 $fld->type = $type; 429 $fld->max_length = -1; 430 } 431 $fld->not_null = ($rs->fields[2] != 'YES'); 432 $fld->primary_key = ($rs->fields[3] == 'PRI'); 433 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); 434 $fld->binary = (strpos($type,'blob') !== false); 435 $fld->unsigned = (strpos($type,'unsigned') !== false); 436 437 if (!$fld->binary) { 438 $d = $rs->fields[4]; 439 if ($d != '' && $d != 'NULL') { 440 $fld->has_default = true; 441 $fld->default_value = $d; 442 } else { 443 $fld->has_default = false; 444 } 445 } 446 447 if ($save == ADODB_FETCH_NUM) { 448 $retarr[] = $fld; 449 } else { 450 $retarr[strtoupper($fld->name)] = $fld; 451 } 452 $rs->MoveNext(); 453 } 454 455 $rs->Close(); 456 return $retarr; 457 } 458 459 // returns true or false 460 function SelectDB($dbName) 461 { 462 $this->database = $dbName; 463 if ($this->_connectionID) { 464 return @mysql_select_db($dbName,$this->_connectionID); 465 } 466 else return false; 467 } 468 469 // parameters use PostgreSQL convention, not MySQL 470 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0) 471 { 472 $offsetStr =($offset>=0) ? "$offset," : ''; 473 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220 474 if ($nrows < 0) $nrows = '18446744073709551615'; 475 476 //if the sql ends by a 'for update' it should be AFTER the LIMIT 477 $FORUPDATE = ''; 478 //with PHP5 we could have used stripos and str_ireplace 479 if ( (strtoupper(substr($sql,-10))) == 'FOR UPDATE') { 480 $sql = substr($sql,0,(strlen($sql)-10)); 481 $FORUPDATE = 'for update'; 482 } elseif ( (strtoupper(substr($sql,-11))) == 'FOR UPDATE;') { 483 $sql = substr($sql,0,(strlen($sql)-11)); 484 $FORUPDATE = 'for update'; 485 } 486 487 if ($secs) 488 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows $FORUPDATE",$inputarr); 489 else 490 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows $FORUPDATE",$inputarr); 491 return $rs; 492 } 493 494 // returns queryID or false 495 function _query($sql,$inputarr) 496 { 497 //global $ADODB_COUNTRECS; 498 //if($ADODB_COUNTRECS) 499 return mysql_query($sql,$this->_connectionID); 500 //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6 501 } 502 503 /* Returns: the last error message from previous database operation */ 504 function ErrorMsg() 505 { 506 507 if ($this->_logsql) return $this->_errorMsg; 508 if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error(); 509 else $this->_errorMsg = @mysql_error($this->_connectionID); 510 return $this->_errorMsg; 511 } 512 513 /* Returns: the last error number from previous database operation */ 514 function ErrorNo() 515 { 516 if ($this->_logsql) return $this->_errorCode; 517 if (empty($this->_connectionID)) return @mysql_errno(); 518 else return @mysql_errno($this->_connectionID); 519 } 520 521 // returns true or false 522 function _close() 523 { 524 @mysql_close($this->_connectionID); 525 $this->_connectionID = false; 526 } 527 528 529 /* 530 * Maximum size of C field 531 */ 532 function CharMax() 533 { 534 return 255; 535 } 536 537 /* 538 * Maximum size of X field 539 */ 540 function TextMax() 541 { 542 return 4294967295; 543 } 544 545 // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx> 546 function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $asociative = FALSE ) 547 { 548 if ( !empty($owner) ) { 549 $table = "$owner.$table"; 550 } 551 $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table)); 552 $create_sql = $a_create_table[1]; 553 554 $matches = array(); 555 $foreign_keys = array(); 556 if ( preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches) ) { 557 $num_keys = count($matches[0]); 558 for ( $i = 0; $i < $num_keys; $i ++ ) { 559 $my_field = explode('`, `', $matches[1][$i]); 560 $ref_table = $matches[2][$i]; 561 $ref_field = explode('`, `', $matches[3][$i]); 562 563 if ( $upper ) { 564 $ref_table = strtoupper($ref_table); 565 } 566 567 $foreign_keys[$ref_table] = array(); 568 $num_fields = count($my_field); 569 for ( $j = 0; $j < $num_fields; $j ++ ) { 570 if ( $asociative ) { 571 $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j]; 572 } else { 573 $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}"; 574 } 575 } 576 } 577 } 578 return $foreign_keys; 579 } 580 581 /** 582 * @var array $charset2mysql translate www charsets to mysql ones 583 */ 584 var $charset2mysql = array( 585 'utf-8' => 'utf8', 586 'iso-8859-1' => 'latin1', 587 'iso-8859-2' => 'latin2', 588 'windows-1251' => 'cp1251', 589 'koi8-r' => 'koi8r', // 4.0: koi8_ru 590 'euc-kr' => 'euckr', // 4.0: euc_kr 591 'euc-jp' => 'ujis', // 4.0: - 592 'iso-8859-7' => 'greek', // 4.0: - 593 ); 594 595 /** 596 * gets the client encoding from the connection 597 * 598 * mysqli_client_encoding only returns the default charset, not the one currently used! 599 * 600 * @return string/boolean charset or false 601 */ 602 function GetCharSet() 603 { 604 $this->charSet = $this->GetOne('SELECT @@character_set_connection'); 605 if ($this->charSet) { 606 $mysql2charset = array_flip($this->charset2mysql); 607 if (isset($mysql2charset[$this->charSet])) { 608 $this->charSet = $mysql2charset[$this->charSet]; 609 } 610 } 611 return $this->charSet ? $this->charSet : false; 612 } 613 614 /** 615 * sets the client encoding from the connection 616 * 617 * @param string $charset_name 618 * @return boolean true on success, false otherwise 619 */ 620 function SetCharSet($charset_name) 621 { 622 $mysql_charset = isset($this->charset2mysql[$charset_name]) ? $this->charset2mysql[$charset_name] : $charset_name; 623 if (!mysql_query('SET NAMES '.$this->qstr($mysql_charset),$this->_connectionID)) return false; 624 if ($this->GetCharSet()) { 625 return $this->charSet == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name; 626 } 627 return false; 628 } 629 } 630 631 632 /*-------------------------------------------------------------------------------------- 633 Class Name: Recordset 634 --------------------------------------------------------------------------------------*/ 635 636 637 class ADORecordSet_mysql extends ADORecordSet{ 638 639 var $databaseType = "mysql"; 640 var $canSeek = true; 641 642 function ADORecordSet_mysql($queryID,$mode=false) 643 { 644 if ($mode === false) { 645 global $ADODB_FETCH_MODE; 646 $mode = $ADODB_FETCH_MODE; 647 } 648 switch ($mode) 649 { 650 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 651 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 652 case ADODB_FETCH_DEFAULT: 653 case ADODB_FETCH_BOTH: 654 default: 655 $this->fetchMode = MYSQL_BOTH; break; 656 } 657 $this->adodbFetchMode = $mode; 658 $this->ADORecordSet($queryID); 659 } 660 661 function _initrs() 662 { 663 //GLOBAL $ADODB_COUNTRECS; 664 // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1; 665 $this->_numOfRows = @mysql_num_rows($this->_queryID); 666 $this->_numOfFields = @mysql_num_fields($this->_queryID); 667 } 668 669 function &FetchField($fieldOffset = -1) 670 { 671 if ($fieldOffset != -1) { 672 $o = @mysql_fetch_field($this->_queryID, $fieldOffset); 673 $f = @mysql_field_flags($this->_queryID,$fieldOffset); 674 $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com) 675 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable 676 $o->binary = (strpos($f,'binary')!== false); 677 } 678 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ 679 $o = @mysql_fetch_field($this->_queryID); 680 $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com) 681 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable 682 } 683 684 return $o; 685 } 686 687 function &GetRowAssoc($upper=true) 688 { 689 if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields; 690 $row =& ADORecordSet::GetRowAssoc($upper); 691 return $row; 692 } 693 694 /* Use associative array to get fields array */ 695 function Fields($colname) 696 { 697 // added @ by "Michael William Miller" <mille562@pilot.msu.edu> 698 if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname]; 699 700 if (!$this->bind) { 701 $this->bind = array(); 702 for ($i=0; $i < $this->_numOfFields; $i++) { 703 $o = $this->FetchField($i); 704 $this->bind[strtoupper($o->name)] = $i; 705 } 706 } 707 return $this->fields[$this->bind[strtoupper($colname)]]; 708 } 709 710 function _seek($row) 711 { 712 if ($this->_numOfRows == 0) return false; 713 return @mysql_data_seek($this->_queryID,$row); 714 } 715 716 function MoveNext() 717 { 718 //return adodb_movenext($this); 719 //if (defined('ADODB_EXTENSION')) return adodb_movenext($this); 720 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) { 721 $this->_currentRow += 1; 722 return true; 723 } 724 if (!$this->EOF) { 725 $this->_currentRow += 1; 726 $this->EOF = true; 727 } 728 return false; 729 } 730 731 function _fetch() 732 { 733 $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode); 734 return is_array($this->fields); 735 } 736 737 function _close() { 738 @mysql_free_result($this->_queryID); 739 $this->_queryID = false; 740 } 741 742 function MetaType($t,$len=-1,$fieldobj=false) 743 { 744 if (is_object($t)) { 745 $fieldobj = $t; 746 $t = $fieldobj->type; 747 $len = $fieldobj->max_length; 748 } 749 750 $len = -1; // mysql max_length is not accurate 751 switch (strtoupper($t)) { 752 case 'STRING': 753 case 'CHAR': 754 case 'VARCHAR': 755 case 'TINYBLOB': 756 case 'TINYTEXT': 757 case 'ENUM': 758 case 'SET': 759 if ($len <= $this->blobSize) return 'C'; 760 761 case 'TEXT': 762 case 'LONGTEXT': 763 case 'MEDIUMTEXT': 764 return 'X'; 765 766 // php_mysql extension always returns 'blob' even if 'text' 767 // so we have to check whether binary... 768 case 'IMAGE': 769 case 'LONGBLOB': 770 case 'BLOB': 771 case 'MEDIUMBLOB': 772 return !empty($fieldobj->binary) ? 'B' : 'X'; 773 774 case 'YEAR': 775 case 'DATE': return 'D'; 776 777 case 'TIME': 778 case 'DATETIME': 779 case 'TIMESTAMP': return 'T'; 780 781 case 'INT': 782 case 'INTEGER': 783 case 'BIGINT': 784 case 'TINYINT': 785 case 'MEDIUMINT': 786 case 'SMALLINT': 787 788 if (!empty($fieldobj->primary_key)) return 'R'; 789 else return 'I'; 790 791 default: return 'N'; 792 } 793 } 794 795 } 796 797 class ADORecordSet_ext_mysql extends ADORecordSet_mysql { 798 function ADORecordSet_ext_mysql($queryID,$mode=false) 799 { 800 if ($mode === false) { 801 global $ADODB_FETCH_MODE; 802 $mode = $ADODB_FETCH_MODE; 803 } 804 switch ($mode) 805 { 806 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break; 807 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break; 808 case ADODB_FETCH_DEFAULT: 809 case ADODB_FETCH_BOTH: 810 default: 811 $this->fetchMode = MYSQL_BOTH; break; 812 } 813 $this->adodbFetchMode = $mode; 814 $this->ADORecordSet($queryID); 815 } 816 817 function MoveNext() 818 { 819 return @adodb_movenext($this); 820 } 821 } 822 823 824 } 825 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |