| [ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 /* 3 V4.94 23 Jan 2007 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved. 4 5 This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension 6 for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or 7 higher. 8 9 Originally tested with PHP 5.1.1 and Apache 2.0.55 on Windows XP SP2. 10 More recently tested with PHP 5.1.2 and Apache 2.0.55 on Windows XP SP2. 11 12 This file was ported from "adodb-odbc.inc.php" by Larry Menard, "larry.menard#rogers.com". 13 I ripped out what I believed to be a lot of redundant or obsolete code, but there are 14 probably still some remnants of the ODBC support in this file; I'm relying on reviewers 15 of this code to point out any other things that can be removed. 16 */ 17 18 // security - hide paths 19 if (!defined('ADODB_DIR')) die(); 20 21 define("_ADODB_DB2_LAYER", 2 ); 22 23 /*-------------------------------------------------------------------------------------- 24 --------------------------------------------------------------------------------------*/ 25 26 27 class ADODB_db2 extends ADOConnection { 28 var $databaseType = "db2"; 29 var $fmtDate = "'Y-m-d'"; 30 var $concat_operator = '||'; 31 32 var $sysTime = 'CURRENT TIME'; 33 var $sysDate = 'CURRENT DATE'; 34 var $sysTimeStamp = 'CURRENT TIMESTAMP'; 35 36 // See #8386 for more details 37 // original: var $fmtTimeStamp = "'Y-m-d-H:i:s'"; 38 // DB2 valid formats: Y-m-d-H.i.s (IBM SQL format, center dash and dots) or Y-m-d H:i:s (ISO format, center space and colons). Since i5/OS v5r3 supports only IBM SQL format, we'll use it: Y-m-d-H.i.s 39 var $fmtTimeStamp = "'Y-m-d-H.i.s'"; 40 var $replaceQuote = "''"; // string to use to replace quotes 41 var $dataProvider = "db2"; 42 var $hasAffectedRows = true; 43 44 var $binmode = DB2_BINARY; 45 46 var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive 47 // breaking backward-compat 48 var $_bindInputArray = false; 49 var $_genIDSQL = "VALUES NEXTVAL FOR %s"; 50 var $_genSeqSQL = "CREATE SEQUENCE %s START WITH 1 NO MAXVALUE NO CYCLE"; 51 var $_dropSeqSQL = "DROP SEQUENCE %s"; 52 var $_autocommit = true; 53 var $_haserrorfunctions = true; 54 var $_lastAffectedRows = 0; 55 var $uCaseTables = true; // for meta* functions, uppercase table names 56 var $hasInsertID = true; 57 58 function _insertid() 59 { 60 // See #8385 for more details. 61 // original: return ADOConnection::GetOne('VALUES IDENTITY_VAL_LOCAL()'); 62 return ADOConnection::GetOne('SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1'); 63 } 64 65 function ADODB_db2() 66 { 67 $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; 68 } 69 70 // returns true or false 71 function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) 72 { 73 global $php_errormsg; 74 75 if (!function_exists('db2_connect')) { 76 ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension."); 77 return null; 78 } 79 // This needs to be set before the connect(). 80 // Replaces the odbc_binmode() call that was in Execute() 81 ini_set('ibm_db2.binmode', $this->binmode); 82 83 if ($argDatabasename) { 84 $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); 85 } else { 86 $this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword); 87 } 88 if (isset($php_errormsg)) $php_errormsg = ''; 89 90 // For db2_connect(), there is an optional 4th arg. If present, it must be 91 // an array of valid options. So far, we don't use them. 92 93 $this->_errorMsg = @db2_conn_errormsg(); 94 95 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 96 97 return $this->_connectionID != false; 98 } 99 100 // returns true or false 101 function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) 102 { 103 global $php_errormsg; 104 105 if (!function_exists('db2_connect')) return null; 106 107 // This needs to be set before the connect(). 108 // Replaces the odbc_binmode() call that was in Execute() 109 ini_set('ibm_db2.binmode', $this->binmode); 110 111 if (isset($php_errormsg)) $php_errormsg = ''; 112 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 113 114 if ($argDatabasename) { 115 $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword); 116 } else { 117 $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword); 118 } 119 if (isset($php_errormsg)) $php_errormsg = ''; 120 121 $this->_errorMsg = @db2_conn_errormsg(); 122 if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID); 123 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 124 125 return $this->_connectionID != false; 126 } 127 128 // format and return date string in database timestamp format 129 function DBTimeStamp($ts) 130 { 131 if (empty($ts) && $ts !== 0) return 'null'; 132 if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); 133 134 // See #8387 for more details 135 // original: return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')"; 136 return adodb_date($this->fmtTimeStamp,$ts); 137 } 138 139 // Format date column in sql string given an input format that understands Y M D 140 function SQLDate($fmt, $col=false) 141 { 142 // use right() and replace() ? 143 if (!$col) $col = $this->sysDate; 144 145 /* use TO_CHAR() if $fmt is TO_CHAR() allowed fmt */ 146 if ($fmt== 'Y-m-d H:i:s') 147 return 'TO_CHAR('.$col.", 'YYYY-MM-DD HH24:MI:SS')"; 148 149 $s = ''; 150 151 $len = strlen($fmt); 152 for ($i=0; $i < $len; $i++) { 153 if ($s) $s .= $this->concat_operator; 154 $ch = $fmt[$i]; 155 switch($ch) { 156 case 'Y': 157 case 'y': 158 if ($len==1) return "year($col)"; 159 $s .= "char(year($col))"; 160 break; 161 case 'M': 162 if ($len==1) return "monthname($col)"; 163 $s .= "substr(monthname($col),1,3)"; 164 break; 165 case 'm': 166 if ($len==1) return "month($col)"; 167 $s .= "right(digits(month($col)),2)"; 168 break; 169 case 'D': 170 case 'd': 171 if ($len==1) return "day($col)"; 172 $s .= "right(digits(day($col)),2)"; 173 break; 174 case 'H': 175 case 'h': 176 if ($len==1) return "hour($col)"; 177 if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)"; 178 else $s .= "''"; 179 break; 180 case 'i': 181 case 'I': 182 if ($len==1) return "minute($col)"; 183 if ($col != $this->sysDate) 184 $s .= "right(digits(minute($col)),2)"; 185 else $s .= "''"; 186 break; 187 case 'S': 188 case 's': 189 if ($len==1) return "second($col)"; 190 if ($col != $this->sysDate) 191 $s .= "right(digits(second($col)),2)"; 192 else $s .= "''"; 193 break; 194 default: 195 if ($ch == '\\') { 196 $i++; 197 $ch = substr($fmt,$i,1); 198 } 199 $s .= $this->qstr($ch); 200 } 201 } 202 return $s; 203 } 204 205 206 function ServerInfo() 207 { 208 209 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { 210 $dsn = strtoupper($this->host); 211 $first = true; 212 $found = false; 213 214 if (!function_exists('db2_data_source')) return false; 215 216 while(true) { 217 218 $rez = @db2_data_source($this->_connectionID, 219 $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT); 220 $first = false; 221 if (!is_array($rez)) break; 222 if (strtoupper($rez['server']) == $dsn) { 223 $found = true; 224 break; 225 } 226 } 227 if (!$found) return ADOConnection::ServerInfo(); 228 if (!isset($rez['version'])) $rez['version'] = ''; 229 return $rez; 230 } else { 231 return ADOConnection::ServerInfo(); 232 } 233 } 234 235 236 function CreateSequence($seqname='adodbseq',$start=1) 237 { 238 if (empty($this->_genSeqSQL)) return false; 239 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 240 if (!$ok) return false; 241 return true; 242 } 243 244 function DropSequence($seqname) 245 { 246 if (empty($this->_dropSeqSQL)) return false; 247 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 248 } 249 250 /* 251 This algorithm is not very efficient, but works even if table locking 252 is not available. 253 254 Will return false if unable to generate an ID after $MAXLOOPS attempts. 255 */ 256 function GenID($seq='adodbseq',$start=1) 257 { 258 // if you have to modify the parameter below, your database is overloaded, 259 // or you need to implement generation of id's yourself! 260 $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); 261 return $num; 262 } 263 264 265 function ErrorMsg() 266 { 267 if ($this->_haserrorfunctions) { 268 if ($this->_errorMsg !== false) return $this->_errorMsg; 269 if (empty($this->_connectionID)) return @db2_conn_errormsg(); 270 return @db2_conn_errormsg($this->_connectionID); 271 } else return ADOConnection::ErrorMsg(); 272 } 273 274 function ErrorNo() 275 { 276 277 if ($this->_haserrorfunctions) { 278 if ($this->_errorCode !== false) { 279 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 280 return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; 281 } 282 283 if (empty($this->_connectionID)) $e = @db2_conn_error(); 284 else $e = @db2_conn_error($this->_connectionID); 285 286 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 287 // so we check and patch 288 if (strlen($e)<=2) return 0; 289 return $e; 290 } else return ADOConnection::ErrorNo(); 291 } 292 293 294 295 function BeginTrans() 296 { 297 if (!$this->hasTransactions) return false; 298 if ($this->transOff) return true; 299 $this->transCnt += 1; 300 $this->_autocommit = false; 301 return db2_autocommit($this->_connectionID,false); 302 } 303 304 function CommitTrans($ok=true) 305 { 306 if ($this->transOff) return true; 307 if (!$ok) return $this->RollbackTrans(); 308 if ($this->transCnt) $this->transCnt -= 1; 309 $this->_autocommit = true; 310 $ret = db2_commit($this->_connectionID); 311 db2_autocommit($this->_connectionID,true); 312 return $ret; 313 } 314 315 function RollbackTrans() 316 { 317 if ($this->transOff) return true; 318 if ($this->transCnt) $this->transCnt -= 1; 319 $this->_autocommit = true; 320 $ret = db2_rollback($this->_connectionID); 321 db2_autocommit($this->_connectionID,true); 322 return $ret; 323 } 324 325 function MetaPrimaryKeys($table) 326 { 327 global $ADODB_FETCH_MODE; 328 329 if ($this->uCaseTables) $table = strtoupper($table); 330 $schema = ''; 331 $this->_findschema($table,$schema); 332 333 $savem = $ADODB_FETCH_MODE; 334 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 335 $qid = @db2_primarykeys($this->_connectionID,'',$schema,$table); 336 337 if (!$qid) { 338 $ADODB_FETCH_MODE = $savem; 339 return false; 340 } 341 $rs = new ADORecordSet_db2($qid); 342 $ADODB_FETCH_MODE = $savem; 343 344 if (!$rs) return false; 345 346 $arr =& $rs->GetArray(); 347 $rs->Close(); 348 $arr2 = array(); 349 for ($i=0; $i < sizeof($arr); $i++) { 350 if ($arr[$i][3]) $arr2[] = $arr[$i][3]; 351 } 352 return $arr2; 353 } 354 355 function MetaForeignKeys($table, $owner = FALSE, $upper = FALSE, $asociative = FALSE ) 356 { 357 global $ADODB_FETCH_MODE; 358 359 if ($this->uCaseTables) $table = strtoupper($table); 360 $schema = ''; 361 $this->_findschema($table,$schema); 362 363 $savem = $ADODB_FETCH_MODE; 364 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 365 $qid = @db2_foreign_keys($this->_connectionID,'',$schema,$table); 366 if (!$qid) { 367 $ADODB_FETCH_MODE = $savem; 368 return false; 369 } 370 $rs = new ADORecordSet_db2($qid); 371 372 $ADODB_FETCH_MODE = $savem; 373 /* 374 $rs->fields indices 375 0 PKTABLE_CAT 376 1 PKTABLE_SCHEM 377 2 PKTABLE_NAME 378 3 PKCOLUMN_NAME 379 4 FKTABLE_CAT 380 5 FKTABLE_SCHEM 381 6 FKTABLE_NAME 382 7 FKCOLUMN_NAME 383 */ 384 if (!$rs) return false; 385 386 $foreign_keys = array(); 387 while (!$rs->EOF) { 388 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 389 if (!is_array($foreign_keys[$rs->fields[5].'.'.$rs->fields[6]])) 390 $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]] = array(); 391 $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]][$rs->fields[7]] = $rs->fields[3]; 392 } 393 $rs->MoveNext(); 394 } 395 396 $rs->Close(); 397 return $foreign_key; 398 } 399 400 401 // See #8384 for more details 402 // @@@ original: function MetaTables($ttype=false,$schema=false) 403 // DB2/400 Allow table and schema as optional parameters. 404 function MetaTables($ttype=false,$showSchema=false, $qtable="%", $qschema="%") 405 { 406 global $ADODB_FETCH_MODE; 407 408 $savem = $ADODB_FETCH_MODE; 409 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 410 411 // @@@ original: $qid = db2_tables($this->_connectionID); 412 $qid = db2_tables($this->_connectionID, null, $qschema, $qtable); 413 414 $rs = new ADORecordSet_db2($qid); 415 416 $ADODB_FETCH_MODE = $savem; 417 if (!$rs) { 418 $false = false; 419 return $false; 420 } 421 422 $arr =& $rs->GetArray(); 423 424 $rs->Close(); 425 $arr2 = array(); 426 427 if ($ttype) { 428 $isview = strncmp($ttype,'V',1) === 0; 429 } 430 for ($i=0; $i < sizeof($arr); $i++) { 431 if (!$arr[$i][2]) continue; 432 $type = $arr[$i][3]; 433 // @@@ original: DB2/400 $schemaval = ($schema) ? $arr[$i][1].'.' : ''; 434 // use $showSchema instead of $schema, for consistency with odbc_db2.inc.php 435 $schemaval = ($showSchema) ? $arr[$i][1].'.' : ''; 436 if ($ttype) { 437 if ($isview) { 438 if (strncmp($type,'V',1) === 0) $arr2[] = $schemaval.$arr[$i][2]; 439 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 440 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 441 } 442 return $arr2; 443 } 444 445 /* 446 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2datetime_data_type_changes.asp 447 / SQL data type codes / 448 #define SQL_UNKNOWN_TYPE 0 449 #define SQL_CHAR 1 450 #define SQL_NUMERIC 2 451 #define SQL_DECIMAL 3 452 #define SQL_INTEGER 4 453 #define SQL_SMALLINT 5 454 #define SQL_FLOAT 6 455 #define SQL_REAL 7 456 #define SQL_DOUBLE 8 457 #if (DB2VER >= 0x0300) 458 #define SQL_DATETIME 9 459 #endif 460 #define SQL_VARCHAR 12 461 462 463 / One-parameter shortcuts for date/time data types / 464 #if (DB2VER >= 0x0300) 465 #define SQL_TYPE_DATE 91 466 #define SQL_TYPE_TIME 92 467 #define SQL_TYPE_TIMESTAMP 93 468 469 #define SQL_UNICODE (-95) 470 #define SQL_UNICODE_VARCHAR (-96) 471 #define SQL_UNICODE_LONGVARCHAR (-97) 472 */ 473 function DB2Types($t) 474 { 475 switch ((integer)$t) { 476 case 1: 477 case 12: 478 case 0: 479 case -95: 480 case -96: 481 return 'C'; 482 case -97: 483 case -1: //text 484 return 'X'; 485 case -4: //image 486 return 'B'; 487 488 case 9: 489 case 91: 490 return 'D'; 491 492 case 10: 493 case 11: 494 case 92: 495 case 93: 496 return 'T'; 497 498 case 4: 499 case 5: 500 case -6: 501 return 'I'; 502 503 case -11: // uniqidentifier 504 return 'R'; 505 case -7: //bit 506 return 'L'; 507 508 default: 509 return 'N'; 510 } 511 } 512 513 function &MetaColumns($table) 514 { 515 global $ADODB_FETCH_MODE; 516 517 $false = false; 518 if ($this->uCaseTables) $table = strtoupper($table); 519 $schema = ''; 520 $this->_findschema($table,$schema); 521 522 $savem = $ADODB_FETCH_MODE; 523 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 524 525 $colname = "%"; 526 $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname); 527 if (empty($qid)) return $false; 528 529 $rs =& new ADORecordSet_db2($qid); 530 $ADODB_FETCH_MODE = $savem; 531 532 if (!$rs) return $false; 533 $rs->_fetch(); 534 535 $retarr = array(); 536 537 /* 538 $rs->fields indices 539 0 TABLE_QUALIFIER 540 1 TABLE_SCHEM 541 2 TABLE_NAME 542 3 COLUMN_NAME 543 4 DATA_TYPE 544 5 TYPE_NAME 545 6 PRECISION 546 7 LENGTH 547 8 SCALE 548 9 RADIX 549 10 NULLABLE 550 11 REMARKS 551 */ 552 while (!$rs->EOF) { 553 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 554 $fld = new ADOFieldObject(); 555 $fld->name = $rs->fields[3]; 556 $fld->type = $this->DB2Types($rs->fields[4]); 557 558 // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp 559 // access uses precision to store length for char/varchar 560 if ($fld->type == 'C' or $fld->type == 'X') { 561 if ($rs->fields[4] <= -95) // UNICODE 562 $fld->max_length = $rs->fields[7]/2; 563 else 564 $fld->max_length = $rs->fields[7]; 565 } else 566 $fld->max_length = $rs->fields[7]; 567 $fld->not_null = !empty($rs->fields[10]); 568 $fld->scale = $rs->fields[8]; 569 $fld->primary_key = false; 570 $retarr[strtoupper($fld->name)] = $fld; 571 } else if (sizeof($retarr)>0) 572 break; 573 $rs->MoveNext(); 574 } 575 $rs->Close(); 576 if (empty($retarr)) $retarr = false; 577 578 $qid = db2_primary_keys($this->_connectionID, "", $schema, $table); 579 if (empty($qid)) return $false; 580 581 $rs =& new ADORecordSet_db2($qid); 582 $ADODB_FETCH_MODE = $savem; 583 584 if (!$rs) return $retarr; 585 $rs->_fetch(); 586 587 /* 588 $rs->fields indices 589 0 TABLE_CAT 590 1 TABLE_SCHEM 591 2 TABLE_NAME 592 3 COLUMN_NAME 593 4 KEY_SEQ 594 5 PK_NAME 595 */ 596 while (!$rs->EOF) { 597 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 598 $retarr[strtoupper($rs->fields[3])]->primary_key = true; 599 } else if (sizeof($retarr)>0) 600 break; 601 $rs->MoveNext(); 602 } 603 $rs->Close(); 604 605 if (empty($retarr)) $retarr = false; 606 return $retarr; 607 } 608 609 function Prepare($sql) 610 { 611 if (! $this->_bindInputArray) return $sql; // no binding 612 $stmt = db2_prepare($this->_connectionID,$sql); 613 if (!$stmt) { 614 // we don't know whether db2 driver is parsing prepared stmts, so just return sql 615 return $sql; 616 } 617 return array($sql,$stmt,false); 618 } 619 620 /* returns queryID or false */ 621 function _query($sql,$inputarr=false) 622 { 623 GLOBAL $php_errormsg; 624 if (isset($php_errormsg)) $php_errormsg = ''; 625 $this->_error = ''; 626 627 if ($inputarr) { 628 if (is_array($sql)) { 629 $stmtid = $sql[1]; 630 } else { 631 $stmtid = db2_prepare($this->_connectionID,$sql); 632 633 if ($stmtid == false) { 634 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 635 return false; 636 } 637 } 638 639 if (! db2_execute($stmtid,$inputarr)) { 640 if ($this->_haserrorfunctions) { 641 $this->_errorMsg = db2_stmt_errormsg(); 642 $this->_errorCode = db2_stmt_error(); 643 } 644 return false; 645 } 646 647 } else if (is_array($sql)) { 648 $stmtid = $sql[1]; 649 if (!db2_execute($stmtid)) { 650 if ($this->_haserrorfunctions) { 651 $this->_errorMsg = db2_stmt_errormsg(); 652 $this->_errorCode = db2_stmt_error(); 653 } 654 return false; 655 } 656 } else 657 $stmtid = @db2_exec($this->_connectionID,$sql); 658 659 $this->_lastAffectedRows = 0; 660 if ($stmtid) { 661 if (@db2_num_fields($stmtid) == 0) { 662 $this->_lastAffectedRows = db2_num_rows($stmtid); 663 $stmtid = true; 664 } else { 665 $this->_lastAffectedRows = 0; 666 } 667 668 if ($this->_haserrorfunctions) { 669 $this->_errorMsg = ''; 670 $this->_errorCode = 0; 671 } else 672 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 673 } else { 674 if ($this->_haserrorfunctions) { 675 $this->_errorMsg = db2_stmt_errormsg(); 676 $this->_errorCode = db2_stmt_error(); 677 } else 678 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 679 680 } 681 return $stmtid; 682 } 683 684 /* 685 Insert a null into the blob field of the table first. 686 Then use UpdateBlob to store the blob. 687 688 Usage: 689 690 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 691 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 692 */ 693 function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 694 { 695 return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; 696 } 697 698 // returns true or false 699 function _close() 700 { 701 $ret = @db2_close($this->_connectionID); 702 $this->_connectionID = false; 703 return $ret; 704 } 705 706 function _affectedrows() 707 { 708 return $this->_lastAffectedRows; 709 } 710 711 } 712 713 /*-------------------------------------------------------------------------------------- 714 Class Name: Recordset 715 --------------------------------------------------------------------------------------*/ 716 717 class ADORecordSet_db2 extends ADORecordSet { 718 719 var $bind = false; 720 var $databaseType = "db2"; 721 var $dataProvider = "db2"; 722 var $useFetchArray; 723 724 function ADORecordSet_db2($id,$mode=false) 725 { 726 if ($mode === false) { 727 global $ADODB_FETCH_MODE; 728 $mode = $ADODB_FETCH_MODE; 729 } 730 $this->fetchMode = $mode; 731 732 $this->_queryID = $id; 733 } 734 735 736 // returns the field object 737 function &FetchField($offset = -1) 738 { 739 $o= new ADOFieldObject(); 740 $o->name = @db2_field_name($this->_queryID,$offset); 741 $o->type = @db2_field_type($this->_queryID,$offset); 742 $o->max_length = db2_field_width($this->_queryID,$offset); 743 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 744 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 745 return $o; 746 } 747 748 /* Use associative array to get fields array */ 749 function Fields($colname) 750 { 751 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 752 if (!$this->bind) { 753 $this->bind = array(); 754 for ($i=0; $i < $this->_numOfFields; $i++) { 755 $o = $this->FetchField($i); 756 $this->bind[strtoupper($o->name)] = $i; 757 } 758 } 759 760 return $this->fields[$this->bind[strtoupper($colname)]]; 761 } 762 763 764 function _initrs() 765 { 766 global $ADODB_COUNTRECS; 767 $this->_numOfRows = ($ADODB_COUNTRECS) ? @db2_num_rows($this->_queryID) : -1; 768 $this->_numOfFields = @db2_num_fields($this->_queryID); 769 // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 770 if ($this->_numOfRows == 0) $this->_numOfRows = -1; 771 } 772 773 function _seek($row) 774 { 775 return false; 776 } 777 778 // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated 779 function &GetArrayLimit($nrows,$offset=-1) 780 { 781 if ($offset <= 0) { 782 $rs =& $this->GetArray($nrows); 783 return $rs; 784 } 785 $savem = $this->fetchMode; 786 $this->fetchMode = ADODB_FETCH_NUM; 787 $this->Move($offset); 788 $this->fetchMode = $savem; 789 790 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 791 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 792 } 793 794 $results = array(); 795 $cnt = 0; 796 while (!$this->EOF && $nrows != $cnt) { 797 $results[$cnt++] = $this->fields; 798 $this->MoveNext(); 799 } 800 801 return $results; 802 } 803 804 805 function MoveNext() 806 { 807 if ($this->_numOfRows != 0 && !$this->EOF) { 808 $this->_currentRow++; 809 810 $this->fields = @db2_fetch_array($this->_queryID); 811 if ($this->fields) { 812 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 813 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 814 } 815 return true; 816 } 817 } 818 $this->fields = false; 819 $this->EOF = true; 820 return false; 821 } 822 823 function _fetch() 824 { 825 826 $this->fields = db2_fetch_array($this->_queryID); 827 if ($this->fields) { 828 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 829 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 830 } 831 return true; 832 } 833 $this->fields = false; 834 return false; 835 } 836 837 function _close() 838 { 839 return @db2_free_result($this->_queryID); 840 } 841 842 } 843 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
|