Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.93 10 Oct 2006 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved. 00004 00005 This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension 00006 for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or 00007 higher. 00008 00009 Originally tested with PHP 5.1.1 and Apache 2.0.55 on Windows XP SP2. 00010 More recently tested with PHP 5.1.2 and Apache 2.0.55 on Windows XP SP2. 00011 00012 This file was ported from "adodb-odbc.inc.php" by Larry Menard, "larry.menard#rogers.com". 00013 I ripped out what I believed to be a lot of redundant or obsolete code, but there are 00014 probably still some remnants of the ODBC support in this file; I'm relying on reviewers 00015 of this code to point out any other things that can be removed. 00016 */ 00017 00018 // security - hide paths 00019 if (!defined('ADODB_DIR')) die(); 00020 00021 define("_ADODB_DB2_LAYER", 2 ); 00022 00023 /*-------------------------------------------------------------------------------------- 00024 --------------------------------------------------------------------------------------*/ 00025 00026 00027 class ADODB_db2 extends ADOConnection { 00028 var $databaseType = "db2"; 00029 var $fmtDate = "'Y-m-d'"; 00030 var $concat_operator = '||'; 00031 00032 var $sysTime = 'CURRENT TIME'; 00033 var $sysDate = 'CURRENT DATE'; 00034 var $sysTimeStamp = 'CURRENT TIMESTAMP'; 00035 00036 var $fmtTimeStamp = "'Y-m-d-H.i.s'"; 00037 var $replaceQuote = "''"; // string to use to replace quotes 00038 var $dataProvider = "db2"; 00039 var $hasAffectedRows = true; 00040 00041 var $binmode = DB2_BINARY; 00042 00043 var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive 00044 // breaking backward-compat 00045 var $_bindInputArray = false; 00046 var $_genIDSQL = "VALUES NEXTVAL FOR %s"; 00047 var $_genSeqSQL = "CREATE SEQUENCE %s START WITH 1 NO MAXVALUE NO CYCLE"; 00048 var $_dropSeqSQL = "DROP SEQUENCE %s"; 00049 var $_autocommit = true; 00050 var $_haserrorfunctions = true; 00051 var $_lastAffectedRows = 0; 00052 var $uCaseTables = true; // for meta* functions, uppercase table names 00053 var $hasInsertID = true; 00054 00055 function _insertid() 00056 { 00057 return ADOConnection::GetOne('VALUES IDENTITY_VAL_LOCAL()'); 00058 } 00059 00060 function ADODB_db2() 00061 { 00062 $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; 00063 } 00064 00065 // returns true or false 00066 function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) 00067 { 00068 global $php_errormsg; 00069 00070 if (!function_exists('db2_connect')) { 00071 ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension."); 00072 return null; 00073 } 00074 // This needs to be set before the connect(). 00075 // Replaces the odbc_binmode() call that was in Execute() 00076 ini_set('ibm_db2.binmode', $this->binmode); 00077 00078 if ($argDatabasename) { 00079 $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); 00080 } else { 00081 $this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword); 00082 } 00083 if (isset($php_errormsg)) $php_errormsg = ''; 00084 00085 // For db2_connect(), there is an optional 4th arg. If present, it must be 00086 // an array of valid options. So far, we don't use them. 00087 00088 $this->_errorMsg = @db2_conn_errormsg(); 00089 00090 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 00091 00092 return $this->_connectionID != false; 00093 } 00094 00095 // returns true or false 00096 function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) 00097 { 00098 global $php_errormsg; 00099 00100 if (!function_exists('db2_connect')) return null; 00101 00102 // This needs to be set before the connect(). 00103 // Replaces the odbc_binmode() call that was in Execute() 00104 ini_set('ibm_db2.binmode', $this->binmode); 00105 00106 if (isset($php_errormsg)) $php_errormsg = ''; 00107 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00108 00109 if ($argDatabasename) { 00110 $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword); 00111 } else { 00112 $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword); 00113 } 00114 if (isset($php_errormsg)) $php_errormsg = ''; 00115 00116 $this->_errorMsg = @db2_conn_errormsg(); 00117 if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID); 00118 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 00119 00120 return $this->_connectionID != false; 00121 } 00122 00123 // format and return date string in database timestamp format 00124 function DBTimeStamp($ts) 00125 { 00126 if (empty($ts) && $ts !== 0) return 'null'; 00127 if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); 00128 return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')"; 00129 } 00130 00131 // Format date column in sql string given an input format that understands Y M D 00132 function SQLDate($fmt, $col=false) 00133 { 00134 // use right() and replace() ? 00135 if (!$col) $col = $this->sysDate; 00136 00137 /* use TO_CHAR() if $fmt is TO_CHAR() allowed fmt */ 00138 if ($fmt== 'Y-m-d H:i:s') 00139 return 'TO_CHAR('.$col.", 'YYYY-MM-DD HH24:MI:SS')"; 00140 00141 $s = ''; 00142 00143 $len = strlen($fmt); 00144 for ($i=0; $i < $len; $i++) { 00145 if ($s) $s .= $this->concat_operator; 00146 $ch = $fmt[$i]; 00147 switch($ch) { 00148 case 'Y': 00149 case 'y': 00150 if ($len==1) return "year($col)"; 00151 $s .= "char(year($col))"; 00152 break; 00153 case 'M': 00154 if ($len==1) return "monthname($col)"; 00155 $s .= "substr(monthname($col),1,3)"; 00156 break; 00157 case 'm': 00158 if ($len==1) return "month($col)"; 00159 $s .= "right(digits(month($col)),2)"; 00160 break; 00161 case 'D': 00162 case 'd': 00163 if ($len==1) return "day($col)"; 00164 $s .= "right(digits(day($col)),2)"; 00165 break; 00166 case 'H': 00167 case 'h': 00168 if ($len==1) return "hour($col)"; 00169 if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)"; 00170 else $s .= "''"; 00171 break; 00172 case 'i': 00173 case 'I': 00174 if ($len==1) return "minute($col)"; 00175 if ($col != $this->sysDate) 00176 $s .= "right(digits(minute($col)),2)"; 00177 else $s .= "''"; 00178 break; 00179 case 'S': 00180 case 's': 00181 if ($len==1) return "second($col)"; 00182 if ($col != $this->sysDate) 00183 $s .= "right(digits(second($col)),2)"; 00184 else $s .= "''"; 00185 break; 00186 default: 00187 if ($ch == '\\') { 00188 $i++; 00189 $ch = substr($fmt,$i,1); 00190 } 00191 $s .= $this->qstr($ch); 00192 } 00193 } 00194 return $s; 00195 } 00196 00197 00198 function ServerInfo() 00199 { 00200 00201 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { 00202 $dsn = strtoupper($this->host); 00203 $first = true; 00204 $found = false; 00205 00206 if (!function_exists('db2_data_source')) return false; 00207 00208 while(true) { 00209 00210 $rez = @db2_data_source($this->_connectionID, 00211 $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT); 00212 $first = false; 00213 if (!is_array($rez)) break; 00214 if (strtoupper($rez['server']) == $dsn) { 00215 $found = true; 00216 break; 00217 } 00218 } 00219 if (!$found) return ADOConnection::ServerInfo(); 00220 if (!isset($rez['version'])) $rez['version'] = ''; 00221 return $rez; 00222 } else { 00223 return ADOConnection::ServerInfo(); 00224 } 00225 } 00226 00227 00228 function CreateSequence($seqname='adodbseq',$start=1) 00229 { 00230 if (empty($this->_genSeqSQL)) return false; 00231 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); 00232 if (!$ok) return false; 00233 return true; 00234 } 00235 00236 function DropSequence($seqname) 00237 { 00238 if (empty($this->_dropSeqSQL)) return false; 00239 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 00240 } 00241 00242 /* 00243 This algorithm is not very efficient, but works even if table locking 00244 is not available. 00245 00246 Will return false if unable to generate an ID after $MAXLOOPS attempts. 00247 */ 00248 function GenID($seq='adodbseq',$start=1) 00249 { 00250 // if you have to modify the parameter below, your database is overloaded, 00251 // or you need to implement generation of id's yourself! 00252 $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); 00253 return $num; 00254 } 00255 00256 00257 function ErrorMsg() 00258 { 00259 if ($this->_haserrorfunctions) { 00260 if ($this->_errorMsg !== false) return $this->_errorMsg; 00261 if (empty($this->_connectionID)) return @db2_conn_errormsg(); 00262 return @db2_conn_errormsg($this->_connectionID); 00263 } else return ADOConnection::ErrorMsg(); 00264 } 00265 00266 function ErrorNo() 00267 { 00268 00269 if ($this->_haserrorfunctions) { 00270 if ($this->_errorCode !== false) { 00271 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 00272 return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; 00273 } 00274 00275 if (empty($this->_connectionID)) $e = @db2_conn_error(); 00276 else $e = @db2_conn_error($this->_connectionID); 00277 00278 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 00279 // so we check and patch 00280 if (strlen($e)<=2) return 0; 00281 return $e; 00282 } else return ADOConnection::ErrorNo(); 00283 } 00284 00285 00286 00287 function BeginTrans() 00288 { 00289 if (!$this->hasTransactions) return false; 00290 if ($this->transOff) return true; 00291 $this->transCnt += 1; 00292 $this->_autocommit = false; 00293 return db2_autocommit($this->_connectionID,false); 00294 } 00295 00296 function CommitTrans($ok=true) 00297 { 00298 if ($this->transOff) return true; 00299 if (!$ok) return $this->RollbackTrans(); 00300 if ($this->transCnt) $this->transCnt -= 1; 00301 $this->_autocommit = true; 00302 $ret = db2_commit($this->_connectionID); 00303 db2_autocommit($this->_connectionID,true); 00304 return $ret; 00305 } 00306 00307 function RollbackTrans() 00308 { 00309 if ($this->transOff) return true; 00310 if ($this->transCnt) $this->transCnt -= 1; 00311 $this->_autocommit = true; 00312 $ret = db2_rollback($this->_connectionID); 00313 db2_autocommit($this->_connectionID,true); 00314 return $ret; 00315 } 00316 00317 function MetaPrimaryKeys($table) 00318 { 00319 global $ADODB_FETCH_MODE; 00320 00321 if ($this->uCaseTables) $table = strtoupper($table); 00322 $schema = ''; 00323 $this->_findschema($table,$schema); 00324 00325 $savem = $ADODB_FETCH_MODE; 00326 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00327 $qid = @db2_primarykeys($this->_connectionID,'',$schema,$table); 00328 00329 if (!$qid) { 00330 $ADODB_FETCH_MODE = $savem; 00331 return false; 00332 } 00333 $rs = new ADORecordSet_db2($qid); 00334 $ADODB_FETCH_MODE = $savem; 00335 00336 if (!$rs) return false; 00337 00338 $arr =& $rs->GetArray(); 00339 $rs->Close(); 00340 $arr2 = array(); 00341 for ($i=0; $i < sizeof($arr); $i++) { 00342 if ($arr[$i][3]) $arr2[] = $arr[$i][3]; 00343 } 00344 return $arr2; 00345 } 00346 00347 function MetaForeignKeys($table, $owner = FALSE, $upper = FALSE, $asociative = FALSE ) 00348 { 00349 global $ADODB_FETCH_MODE; 00350 00351 if ($this->uCaseTables) $table = strtoupper($table); 00352 $schema = ''; 00353 $this->_findschema($table,$schema); 00354 00355 $savem = $ADODB_FETCH_MODE; 00356 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00357 $qid = @db2_foreign_keys($this->_connectionID,'',$schema,$table); 00358 if (!$qid) { 00359 $ADODB_FETCH_MODE = $savem; 00360 return false; 00361 } 00362 $rs = new ADORecordSet_db2($qid); 00363 00364 $ADODB_FETCH_MODE = $savem; 00365 /* 00366 $rs->fields indices 00367 0 PKTABLE_CAT 00368 1 PKTABLE_SCHEM 00369 2 PKTABLE_NAME 00370 3 PKCOLUMN_NAME 00371 4 FKTABLE_CAT 00372 5 FKTABLE_SCHEM 00373 6 FKTABLE_NAME 00374 7 FKCOLUMN_NAME 00375 */ 00376 if (!$rs) return false; 00377 00378 $foreign_keys = array(); 00379 while (!$rs->EOF) { 00380 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 00381 if (!is_array($foreign_keys[$rs->fields[5].'.'.$rs->fields[6]])) 00382 $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]] = array(); 00383 $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]][$rs->fields[7]] = $rs->fields[3]; 00384 } 00385 $rs->MoveNext(); 00386 } 00387 00388 $rs->Close(); 00389 return $foreign_key; 00390 } 00391 00392 00393 function &MetaTables($ttype=false,$schema=false) 00394 { 00395 global $ADODB_FETCH_MODE; 00396 00397 $savem = $ADODB_FETCH_MODE; 00398 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00399 $qid = db2_tables($this->_connectionID); 00400 00401 $rs = new ADORecordSet_db2($qid); 00402 00403 $ADODB_FETCH_MODE = $savem; 00404 if (!$rs) { 00405 $false = false; 00406 return $false; 00407 } 00408 00409 $arr =& $rs->GetArray(); 00410 00411 $rs->Close(); 00412 $arr2 = array(); 00413 00414 if ($ttype) { 00415 $isview = strncmp($ttype,'V',1) === 0; 00416 } 00417 for ($i=0; $i < sizeof($arr); $i++) { 00418 if (!$arr[$i][2]) continue; 00419 $type = $arr[$i][3]; 00420 $schemaval = ($schema) ? $arr[$i][1].'.' : ''; 00421 if ($ttype) { 00422 if ($isview) { 00423 if (strncmp($type,'V',1) === 0) $arr2[] = $schemaval.$arr[$i][2]; 00424 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 00425 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; 00426 } 00427 return $arr2; 00428 } 00429 00430 /* 00431 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2datetime_data_type_changes.asp 00432 / SQL data type codes / 00433 #define SQL_UNKNOWN_TYPE 0 00434 #define SQL_CHAR 1 00435 #define SQL_NUMERIC 2 00436 #define SQL_DECIMAL 3 00437 #define SQL_INTEGER 4 00438 #define SQL_SMALLINT 5 00439 #define SQL_FLOAT 6 00440 #define SQL_REAL 7 00441 #define SQL_DOUBLE 8 00442 #if (DB2VER >= 0x0300) 00443 #define SQL_DATETIME 9 00444 #endif 00445 #define SQL_VARCHAR 12 00446 00447 00448 / One-parameter shortcuts for date/time data types / 00449 #if (DB2VER >= 0x0300) 00450 #define SQL_TYPE_DATE 91 00451 #define SQL_TYPE_TIME 92 00452 #define SQL_TYPE_TIMESTAMP 93 00453 00454 #define SQL_UNICODE (-95) 00455 #define SQL_UNICODE_VARCHAR (-96) 00456 #define SQL_UNICODE_LONGVARCHAR (-97) 00457 */ 00458 function DB2Types($t) 00459 { 00460 switch ((integer)$t) { 00461 case 1: 00462 case 12: 00463 case 0: 00464 case -95: 00465 case -96: 00466 return 'C'; 00467 case -97: 00468 case -1: //text 00469 return 'X'; 00470 case -4: //image 00471 return 'B'; 00472 00473 case 9: 00474 case 91: 00475 return 'D'; 00476 00477 case 10: 00478 case 11: 00479 case 92: 00480 case 93: 00481 return 'T'; 00482 00483 case 4: 00484 case 5: 00485 case -6: 00486 return 'I'; 00487 00488 case -11: // uniqidentifier 00489 return 'R'; 00490 case -7: //bit 00491 return 'L'; 00492 00493 default: 00494 return 'N'; 00495 } 00496 } 00497 00498 function &MetaColumns($table) 00499 { 00500 global $ADODB_FETCH_MODE; 00501 00502 $false = false; 00503 if ($this->uCaseTables) $table = strtoupper($table); 00504 $schema = ''; 00505 $this->_findschema($table,$schema); 00506 00507 $savem = $ADODB_FETCH_MODE; 00508 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00509 00510 $colname = "%"; 00511 $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname); 00512 if (empty($qid)) return $false; 00513 00514 $rs =& new ADORecordSet_db2($qid); 00515 $ADODB_FETCH_MODE = $savem; 00516 00517 if (!$rs) return $false; 00518 $rs->_fetch(); 00519 00520 $retarr = array(); 00521 00522 /* 00523 $rs->fields indices 00524 0 TABLE_QUALIFIER 00525 1 TABLE_SCHEM 00526 2 TABLE_NAME 00527 3 COLUMN_NAME 00528 4 DATA_TYPE 00529 5 TYPE_NAME 00530 6 PRECISION 00531 7 LENGTH 00532 8 SCALE 00533 9 RADIX 00534 10 NULLABLE 00535 11 REMARKS 00536 */ 00537 while (!$rs->EOF) { 00538 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 00539 $fld = new ADOFieldObject(); 00540 $fld->name = $rs->fields[3]; 00541 $fld->type = $this->DB2Types($rs->fields[4]); 00542 00543 // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp 00544 // access uses precision to store length for char/varchar 00545 if ($fld->type == 'C' or $fld->type == 'X') { 00546 if ($rs->fields[4] <= -95) // UNICODE 00547 $fld->max_length = $rs->fields[7]/2; 00548 else 00549 $fld->max_length = $rs->fields[7]; 00550 } else 00551 $fld->max_length = $rs->fields[7]; 00552 $fld->not_null = !empty($rs->fields[10]); 00553 $fld->scale = $rs->fields[8]; 00554 $fld->primary_key = false; 00555 $retarr[strtoupper($fld->name)] = $fld; 00556 } else if (sizeof($retarr)>0) 00557 break; 00558 $rs->MoveNext(); 00559 } 00560 $rs->Close(); 00561 if (empty($retarr)) $retarr = false; 00562 00563 $qid = db2_primary_keys($this->_connectionID, "", $schema, $table); 00564 if (empty($qid)) return $false; 00565 00566 $rs =& new ADORecordSet_db2($qid); 00567 $ADODB_FETCH_MODE = $savem; 00568 00569 if (!$rs) return $retarr; 00570 $rs->_fetch(); 00571 00572 /* 00573 $rs->fields indices 00574 0 TABLE_CAT 00575 1 TABLE_SCHEM 00576 2 TABLE_NAME 00577 3 COLUMN_NAME 00578 4 KEY_SEQ 00579 5 PK_NAME 00580 */ 00581 while (!$rs->EOF) { 00582 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 00583 $retarr[strtoupper($rs->fields[3])]->primary_key = true; 00584 } else if (sizeof($retarr)>0) 00585 break; 00586 $rs->MoveNext(); 00587 } 00588 $rs->Close(); 00589 00590 if (empty($retarr)) $retarr = false; 00591 return $retarr; 00592 } 00593 00594 function Prepare($sql) 00595 { 00596 if (! $this->_bindInputArray) return $sql; // no binding 00597 $stmt = db2_prepare($this->_connectionID,$sql); 00598 if (!$stmt) { 00599 // we don't know whether db2 driver is parsing prepared stmts, so just return sql 00600 return $sql; 00601 } 00602 return array($sql,$stmt,false); 00603 } 00604 00605 /* returns queryID or false */ 00606 function _query($sql,$inputarr=false) 00607 { 00608 GLOBAL $php_errormsg; 00609 if (isset($php_errormsg)) $php_errormsg = ''; 00610 $this->_error = ''; 00611 00612 if ($inputarr) { 00613 if (is_array($sql)) { 00614 $stmtid = $sql[1]; 00615 } else { 00616 $stmtid = db2_prepare($this->_connectionID,$sql); 00617 00618 if ($stmtid == false) { 00619 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00620 return false; 00621 } 00622 } 00623 00624 if (! db2_execute($stmtid,$inputarr)) { 00625 if ($this->_haserrorfunctions) { 00626 $this->_errorMsg = db2_stmt_errormsg(); 00627 $this->_errorCode = db2_stmt_error(); 00628 } 00629 return false; 00630 } 00631 00632 } else if (is_array($sql)) { 00633 $stmtid = $sql[1]; 00634 if (!db2_execute($stmtid)) { 00635 if ($this->_haserrorfunctions) { 00636 $this->_errorMsg = db2_stmt_errormsg(); 00637 $this->_errorCode = db2_stmt_error(); 00638 } 00639 return false; 00640 } 00641 } else 00642 $stmtid = @db2_exec($this->_connectionID,$sql); 00643 00644 $this->_lastAffectedRows = 0; 00645 if ($stmtid) { 00646 if (@db2_num_fields($stmtid) == 0) { 00647 $this->_lastAffectedRows = db2_num_rows($stmtid); 00648 $stmtid = true; 00649 } else { 00650 $this->_lastAffectedRows = 0; 00651 } 00652 00653 if ($this->_haserrorfunctions) { 00654 $this->_errorMsg = ''; 00655 $this->_errorCode = 0; 00656 } else 00657 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00658 } else { 00659 if ($this->_haserrorfunctions) { 00660 $this->_errorMsg = db2_stmt_errormsg(); 00661 $this->_errorCode = db2_stmt_error(); 00662 } else 00663 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00664 00665 } 00666 return $stmtid; 00667 } 00668 00669 /* 00670 Insert a null into the blob field of the table first. 00671 Then use UpdateBlob to store the blob. 00672 00673 Usage: 00674 00675 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 00676 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 00677 */ 00678 function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 00679 { 00680 return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; 00681 } 00682 00683 // returns true or false 00684 function _close() 00685 { 00686 $ret = @db2_close($this->_connectionID); 00687 $this->_connectionID = false; 00688 return $ret; 00689 } 00690 00691 function _affectedrows() 00692 { 00693 return $this->_lastAffectedRows; 00694 } 00695 00696 } 00697 00698 /*-------------------------------------------------------------------------------------- 00699 Class Name: Recordset 00700 --------------------------------------------------------------------------------------*/ 00701 00702 class ADORecordSet_db2 extends ADORecordSet { 00703 00704 var $bind = false; 00705 var $databaseType = "db2"; 00706 var $dataProvider = "db2"; 00707 var $useFetchArray; 00708 00709 function ADORecordSet_db2($id,$mode=false) 00710 { 00711 if ($mode === false) { 00712 global $ADODB_FETCH_MODE; 00713 $mode = $ADODB_FETCH_MODE; 00714 } 00715 $this->fetchMode = $mode; 00716 00717 $this->_queryID = $id; 00718 } 00719 00720 00721 // returns the field object 00722 function &FetchField($offset = -1) 00723 { 00724 $o= new ADOFieldObject(); 00725 $o->name = @db2_field_name($this->_queryID,$offset); 00726 $o->type = @db2_field_type($this->_queryID,$offset); 00727 $o->max_length = db2_field_width($this->_queryID,$offset); 00728 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 00729 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 00730 return $o; 00731 } 00732 00733 /* Use associative array to get fields array */ 00734 function Fields($colname) 00735 { 00736 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 00737 if (!$this->bind) { 00738 $this->bind = array(); 00739 for ($i=0; $i < $this->_numOfFields; $i++) { 00740 $o = $this->FetchField($i); 00741 $this->bind[strtoupper($o->name)] = $i; 00742 } 00743 } 00744 00745 return $this->fields[$this->bind[strtoupper($colname)]]; 00746 } 00747 00748 00749 function _initrs() 00750 { 00751 global $ADODB_COUNTRECS; 00752 $this->_numOfRows = ($ADODB_COUNTRECS) ? @db2_num_rows($this->_queryID) : -1; 00753 $this->_numOfFields = @db2_num_fields($this->_queryID); 00754 // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 00755 if ($this->_numOfRows == 0) $this->_numOfRows = -1; 00756 } 00757 00758 function _seek($row) 00759 { 00760 return false; 00761 } 00762 00763 // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated 00764 function &GetArrayLimit($nrows,$offset=-1) 00765 { 00766 if ($offset <= 0) { 00767 $rs =& $this->GetArray($nrows); 00768 return $rs; 00769 } 00770 $savem = $this->fetchMode; 00771 $this->fetchMode = ADODB_FETCH_NUM; 00772 $this->Move($offset); 00773 $this->fetchMode = $savem; 00774 00775 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00776 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00777 } 00778 00779 $results = array(); 00780 $cnt = 0; 00781 while (!$this->EOF && $nrows != $cnt) { 00782 $results[$cnt++] = $this->fields; 00783 $this->MoveNext(); 00784 } 00785 00786 return $results; 00787 } 00788 00789 00790 function MoveNext() 00791 { 00792 if ($this->_numOfRows != 0 && !$this->EOF) { 00793 $this->_currentRow++; 00794 00795 $this->fields = @db2_fetch_array($this->_queryID); 00796 if ($this->fields) { 00797 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00798 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00799 } 00800 return true; 00801 } 00802 } 00803 $this->fields = false; 00804 $this->EOF = true; 00805 return false; 00806 } 00807 00808 function _fetch() 00809 { 00810 00811 $this->fields = db2_fetch_array($this->_queryID); 00812 if ($this->fields) { 00813 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00814 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00815 } 00816 return true; 00817 } 00818 $this->fields = false; 00819 return false; 00820 } 00821 00822 function _close() 00823 { 00824 return @db2_free_result($this->_queryID); 00825 } 00826 00827 } 00828 ?>