|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 00004 Portions Copyright (c) 2007-2009, iAnywhere Solutions, Inc. 00005 All rights reserved. All unpublished rights reserved. 00006 00007 Released under both BSD license and Lesser GPL library license. 00008 Whenever there is any discrepancy between the two licenses, 00009 the BSD license will take precedence. 00010 00011 Set tabs to 4 for best viewing. 00012 00013 00014 NOTE: This driver requires the Advantage PHP client libraries, which 00015 can be downloaded for free via: 00016 http://devzone.advantagedatabase.com/dz/content.aspx?key=20 00017 00018 DELPHI FOR PHP USERS: 00019 The following steps can be taken to utilize this driver from the 00020 CodeGear Delphi for PHP product: 00021 1 - See note above, download and install the Advantage PHP client. 00022 2 - Copy the following files to the Delphi for PHP\X.X\php\ext directory: 00023 ace32.dll 00024 axcws32.dll 00025 adsloc32.dll 00026 php_advantage.dll (rename the existing php_advantage.dll.5.x.x file) 00027 3 - Add the following line to the Delphi for PHP\X.X\php\php.ini.template file: 00028 extension=php_advantage.dll 00029 4 - To use: enter "ads" as the DriverName on a connection component, and set 00030 a Host property similar to "DataDirectory=c:\". See the Advantage PHP 00031 help file topic for ads_connect for details on connection path options 00032 and formatting. 00033 5 - (optional) - Modify the Delphi for PHP\X.X\vcl\packages\database.packages.php 00034 file and add ads to the list of strings returned when registering the 00035 Database object's DriverName property. 00036 00037 */ 00038 // security - hide paths 00039 if (!defined('ADODB_DIR')) die(); 00040 00041 define("_ADODB_ADS_LAYER", 2 ); 00042 00043 /*-------------------------------------------------------------------------------------- 00044 --------------------------------------------------------------------------------------*/ 00045 00046 00047 class ADODB_ads extends ADOConnection { 00048 var $databaseType = "ads"; 00049 var $fmt = "'m-d-Y'"; 00050 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 00051 var $concat_operator = ''; 00052 var $replaceQuote = "''"; // string to use to replace quotes 00053 var $dataProvider = "ads"; 00054 var $hasAffectedRows = true; 00055 var $binmode = ODBC_BINMODE_RETURN; 00056 var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive 00057 // breaking backward-compat 00058 //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field 00059 var $_bindInputArray = false; 00060 var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L 00061 var $_genSeqSQL = "create table %s (id integer)"; 00062 var $_autocommit = true; 00063 var $_haserrorfunctions = true; 00064 var $_has_stupid_odbc_fetch_api_change = true; 00065 var $_lastAffectedRows = 0; 00066 var $uCaseTables = true; // for meta* functions, uppercase table names 00067 00068 00069 function ADODB_ads() 00070 { 00071 $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; 00072 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; 00073 } 00074 00075 // returns true or false 00076 function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) 00077 { 00078 global $php_errormsg; 00079 00080 if (!function_exists('ads_connect')) return null; 00081 00082 if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { 00083 ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); 00084 } 00085 if (isset($php_errormsg)) $php_errormsg = ''; 00086 if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); 00087 else $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword,$this->curmode); 00088 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00089 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 00090 00091 return $this->_connectionID != false; 00092 } 00093 00094 // returns true or false 00095 function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) 00096 { 00097 global $php_errormsg; 00098 00099 if (!function_exists('ads_connect')) return null; 00100 00101 if (isset($php_errormsg)) $php_errormsg = ''; 00102 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00103 if ($this->debug && $argDatabasename) { 00104 ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); 00105 } 00106 // print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush(); 00107 if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); 00108 else $this->_connectionID = ads_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); 00109 00110 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00111 if ($this->_connectionID && $this->autoRollback) @ads_rollback($this->_connectionID); 00112 if (isset($this->connectStmt)) $this->Execute($this->connectStmt); 00113 00114 return $this->_connectionID != false; 00115 } 00116 00117 // returns the Server version and Description 00118 function ServerInfo() 00119 { 00120 00121 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { 00122 $stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()'); 00123 $res = $this->Execute($stmt); 00124 if(!$res) 00125 print $this->ErrorMsg(); 00126 else{ 00127 $ret["version"]= $res->fields[3]; 00128 $ret["description"]="Advantage Database Server"; 00129 return $ret; 00130 } 00131 } 00132 else { 00133 return ADOConnection::ServerInfo(); 00134 } 00135 } 00136 00137 00138 // returns true or false 00139 function CreateSequence( $seqname,$start=1) 00140 { 00141 $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); 00142 if(!$res){ 00143 print $this->ErrorMsg(); 00144 return false; 00145 } 00146 else 00147 return true; 00148 00149 } 00150 00151 // returns true or false 00152 function DropSequence($seqname) 00153 { 00154 $res = $this->Execute("DROP TABLE $seqname"); 00155 if(!$res){ 00156 print $this->ErrorMsg(); 00157 return false; 00158 } 00159 else 00160 return true; 00161 } 00162 00163 00164 // returns the generated ID or false 00165 // checks if the table already exists, else creates the table and inserts a record into the table 00166 // and gets the ID number of the last inserted record. 00167 function GenID($seqname,$start=1) 00168 { 00169 $go = $this->Execute("select * from $seqname"); 00170 if (!$go){ 00171 $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); 00172 if(!res){ 00173 print $this->ErrorMsg(); 00174 return false; 00175 } 00176 } 00177 $res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )"); 00178 if(!$res){ 00179 print $this->ErrorMsg(); 00180 return false; 00181 } 00182 else{ 00183 $gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota"); 00184 $ret = $gen->fields[0]; 00185 return $ret; 00186 } 00187 00188 } 00189 00190 00191 00192 00193 function ErrorMsg() 00194 { 00195 if ($this->_haserrorfunctions) { 00196 if ($this->_errorMsg !== false) return $this->_errorMsg; 00197 if (empty($this->_connectionID)) return @ads_errormsg(); 00198 return @ads_errormsg($this->_connectionID); 00199 } else return ADOConnection::ErrorMsg(); 00200 } 00201 00202 00203 function ErrorNo() 00204 { 00205 00206 if ($this->_haserrorfunctions) { 00207 if ($this->_errorCode !== false) { 00208 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 00209 return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; 00210 } 00211 00212 if (empty($this->_connectionID)) $e = @ads_error(); 00213 else $e = @ads_error($this->_connectionID); 00214 00215 // bug in 4.0.6, error number can be corrupted string (should be 6 digits) 00216 // so we check and patch 00217 if (strlen($e)<=2) return 0; 00218 return $e; 00219 } else return ADOConnection::ErrorNo(); 00220 } 00221 00222 00223 00224 function BeginTrans() 00225 { 00226 if (!$this->hasTransactions) return false; 00227 if ($this->transOff) return true; 00228 $this->transCnt += 1; 00229 $this->_autocommit = false; 00230 return ads_autocommit($this->_connectionID,false); 00231 } 00232 00233 function CommitTrans($ok=true) 00234 { 00235 if ($this->transOff) return true; 00236 if (!$ok) return $this->RollbackTrans(); 00237 if ($this->transCnt) $this->transCnt -= 1; 00238 $this->_autocommit = true; 00239 $ret = ads_commit($this->_connectionID); 00240 ads_autocommit($this->_connectionID,true); 00241 return $ret; 00242 } 00243 00244 function RollbackTrans() 00245 { 00246 if ($this->transOff) return true; 00247 if ($this->transCnt) $this->transCnt -= 1; 00248 $this->_autocommit = true; 00249 $ret = ads_rollback($this->_connectionID); 00250 ads_autocommit($this->_connectionID,true); 00251 return $ret; 00252 } 00253 00254 00255 // Returns tables,Views or both on succesfull execution. Returns 00256 // tables by default on succesfull execustion. 00257 function &MetaTables($ttype) 00258 { 00259 $recordSet1 = $this->Execute("select * from system.tables"); 00260 if(!$recordSet1){ 00261 print $this->ErrorMsg(); 00262 return false; 00263 } 00264 $recordSet2 = $this->Execute("select * from system.views"); 00265 if(!$recordSet2){ 00266 print $this->ErrorMsg(); 00267 return false; 00268 } 00269 $i=0; 00270 while (!$recordSet1->EOF){ 00271 $arr["$i"] = $recordSet1->fields[0]; 00272 $recordSet1->MoveNext(); 00273 $i=$i+1; 00274 } 00275 if($ttype=='FALSE'){ 00276 while (!$recordSet2->EOF){ 00277 $arr["$i"] = $recordSet2->fields[0]; 00278 $recordSet2->MoveNext(); 00279 $i=$i+1; 00280 } 00281 return $arr; 00282 } 00283 elseif($ttype=='VIEWS'){ 00284 while (!$recordSet2->EOF){ 00285 $arrV["$i"] = $recordSet2->fields[0]; 00286 $recordSet2->MoveNext(); 00287 $i=$i+1; 00288 } 00289 return $arrV; 00290 } 00291 else{ 00292 return $arr; 00293 } 00294 00295 } 00296 00297 function &MetaPrimaryKeys($table) 00298 { 00299 $recordSet = $this->Execute("select table_primary_key from system.tables where name='$table'"); 00300 if(!$recordSet){ 00301 print $this->ErrorMsg(); 00302 return false; 00303 } 00304 $i=0; 00305 while (!$recordSet->EOF){ 00306 $arr["$i"] = $recordSet->fields[0]; 00307 $recordSet->MoveNext(); 00308 $i=$i+1; 00309 } 00310 return $arr; 00311 } 00312 00313 /* 00314 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp 00315 / SQL data type codes / 00316 #define SQL_UNKNOWN_TYPE 0 00317 #define SQL_CHAR 1 00318 #define SQL_NUMERIC 2 00319 #define SQL_DECIMAL 3 00320 #define SQL_INTEGER 4 00321 #define SQL_SMALLINT 5 00322 #define SQL_FLOAT 6 00323 #define SQL_REAL 7 00324 #define SQL_DOUBLE 8 00325 #if (ODBCVER >= 0x0300) 00326 #define SQL_DATETIME 9 00327 #endif 00328 #define SQL_VARCHAR 12 00329 00330 00331 / One-parameter shortcuts for date/time data types / 00332 #if (ODBCVER >= 0x0300) 00333 #define SQL_TYPE_DATE 91 00334 #define SQL_TYPE_TIME 92 00335 #define SQL_TYPE_TIMESTAMP 93 00336 00337 #define SQL_UNICODE (-95) 00338 #define SQL_UNICODE_VARCHAR (-96) 00339 #define SQL_UNICODE_LONGVARCHAR (-97) 00340 */ 00341 function ODBCTypes($t) 00342 { 00343 switch ((integer)$t) { 00344 case 1: 00345 case 12: 00346 case 0: 00347 case -95: 00348 case -96: 00349 return 'C'; 00350 case -97: 00351 case -1: //text 00352 return 'X'; 00353 case -4: //image 00354 return 'B'; 00355 00356 case 9: 00357 case 91: 00358 return 'D'; 00359 00360 case 10: 00361 case 11: 00362 case 92: 00363 case 93: 00364 return 'T'; 00365 00366 case 4: 00367 case 5: 00368 case -6: 00369 return 'I'; 00370 00371 case -11: // uniqidentifier 00372 return 'R'; 00373 case -7: //bit 00374 return 'L'; 00375 00376 default: 00377 return 'N'; 00378 } 00379 } 00380 00381 function &MetaColumns($table) 00382 { 00383 global $ADODB_FETCH_MODE; 00384 00385 $false = false; 00386 if ($this->uCaseTables) $table = strtoupper($table); 00387 $schema = ''; 00388 $this->_findschema($table,$schema); 00389 00390 $savem = $ADODB_FETCH_MODE; 00391 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00392 00393 /*if (false) { // after testing, confirmed that the following does not work becoz of a bug 00394 $qid2 = ads_tables($this->_connectionID); 00395 $rs = new ADORecordSet_ads($qid2); 00396 $ADODB_FETCH_MODE = $savem; 00397 if (!$rs) return false; 00398 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; 00399 $rs->_fetch(); 00400 00401 while (!$rs->EOF) { 00402 if ($table == strtoupper($rs->fields[2])) { 00403 $q = $rs->fields[0]; 00404 $o = $rs->fields[1]; 00405 break; 00406 } 00407 $rs->MoveNext(); 00408 } 00409 $rs->Close(); 00410 00411 $qid = ads_columns($this->_connectionID,$q,$o,strtoupper($table),'%'); 00412 } */ 00413 00414 switch ($this->databaseType) { 00415 case 'access': 00416 case 'vfp': 00417 $qid = ads_columns($this->_connectionID);#,'%','',strtoupper($table),'%'); 00418 break; 00419 00420 00421 case 'db2': 00422 $colname = "%"; 00423 $qid = ads_columns($this->_connectionID, "", $schema, $table, $colname); 00424 break; 00425 00426 default: 00427 $qid = @ads_columns($this->_connectionID,'%','%',strtoupper($table),'%'); 00428 if (empty($qid)) $qid = ads_columns($this->_connectionID); 00429 break; 00430 } 00431 if (empty($qid)) return $false; 00432 00433 $rs = new ADORecordSet_ads($qid); 00434 $ADODB_FETCH_MODE = $savem; 00435 00436 if (!$rs) return $false; 00437 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; 00438 $rs->_fetch(); 00439 00440 $retarr = array(); 00441 00442 /* 00443 $rs->fields indices 00444 0 TABLE_QUALIFIER 00445 1 TABLE_SCHEM 00446 2 TABLE_NAME 00447 3 COLUMN_NAME 00448 4 DATA_TYPE 00449 5 TYPE_NAME 00450 6 PRECISION 00451 7 LENGTH 00452 8 SCALE 00453 9 RADIX 00454 10 NULLABLE 00455 11 REMARKS 00456 */ 00457 while (!$rs->EOF) { 00458 // adodb_pr($rs->fields); 00459 if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { 00460 $fld = new ADOFieldObject(); 00461 $fld->name = $rs->fields[3]; 00462 $fld->type = $this->ODBCTypes($rs->fields[4]); 00463 00464 // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp 00465 // access uses precision to store length for char/varchar 00466 if ($fld->type == 'C' or $fld->type == 'X') { 00467 if ($this->databaseType == 'access') 00468 $fld->max_length = $rs->fields[6]; 00469 else if ($rs->fields[4] <= -95) // UNICODE 00470 $fld->max_length = $rs->fields[7]/2; 00471 else 00472 $fld->max_length = $rs->fields[7]; 00473 } else 00474 $fld->max_length = $rs->fields[7]; 00475 $fld->not_null = !empty($rs->fields[10]); 00476 $fld->scale = $rs->fields[8]; 00477 $retarr[strtoupper($fld->name)] = $fld; 00478 } else if (sizeof($retarr)>0) 00479 break; 00480 $rs->MoveNext(); 00481 } 00482 $rs->Close(); //-- crashes 4.03pl1 -- why? 00483 00484 if (empty($retarr)) $retarr = false; 00485 return $retarr; 00486 } 00487 00488 // Returns an array of columns names for a given table 00489 function &MetaColumnNames($table) 00490 { 00491 $recordSet = $this->Execute("select name from system.columns where parent='$table'"); 00492 if(!$recordSet){ 00493 print $this->ErrorMsg(); 00494 return false; 00495 } 00496 else{ 00497 $i=0; 00498 while (!$recordSet->EOF){ 00499 $arr["FIELD$i"] = $recordSet->fields[0]; 00500 $recordSet->MoveNext(); 00501 $i=$i+1; 00502 } 00503 return $arr; 00504 } 00505 } 00506 00507 00508 function Prepare($sql) 00509 { 00510 if (! $this->_bindInputArray) return $sql; // no binding 00511 $stmt = ads_prepare($this->_connectionID,$sql); 00512 if (!$stmt) { 00513 // we don't know whether odbc driver is parsing prepared stmts, so just return sql 00514 return $sql; 00515 } 00516 return array($sql,$stmt,false); 00517 } 00518 00519 /* returns queryID or false */ 00520 function _query($sql,$inputarr=false) 00521 { 00522 GLOBAL $php_errormsg; 00523 if (isset($php_errormsg)) $php_errormsg = ''; 00524 $this->_error = ''; 00525 00526 if ($inputarr) { 00527 if (is_array($sql)) { 00528 $stmtid = $sql[1]; 00529 } else { 00530 $stmtid = ads_prepare($this->_connectionID,$sql); 00531 00532 if ($stmtid == false) { 00533 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00534 return false; 00535 } 00536 } 00537 00538 if (! ads_execute($stmtid,$inputarr)) { 00539 //@ads_free_result($stmtid); 00540 if ($this->_haserrorfunctions) { 00541 $this->_errorMsg = ads_errormsg(); 00542 $this->_errorCode = ads_error(); 00543 } 00544 return false; 00545 } 00546 00547 } else if (is_array($sql)) { 00548 $stmtid = $sql[1]; 00549 if (!ads_execute($stmtid)) { 00550 //@ads_free_result($stmtid); 00551 if ($this->_haserrorfunctions) { 00552 $this->_errorMsg = ads_errormsg(); 00553 $this->_errorCode = ads_error(); 00554 } 00555 return false; 00556 } 00557 } else 00558 { 00559 00560 $stmtid = ads_exec($this->_connectionID,$sql); 00561 00562 } 00563 00564 $this->_lastAffectedRows = 0; 00565 00566 if ($stmtid) 00567 { 00568 00569 if (@ads_num_fields($stmtid) == 0) { 00570 $this->_lastAffectedRows = ads_num_rows($stmtid); 00571 $stmtid = true; 00572 00573 } else { 00574 00575 $this->_lastAffectedRows = 0; 00576 ads_binmode($stmtid,$this->binmode); 00577 ads_longreadlen($stmtid,$this->maxblobsize); 00578 00579 } 00580 00581 if ($this->_haserrorfunctions) 00582 { 00583 00584 $this->_errorMsg = ''; 00585 $this->_errorCode = 0; 00586 } 00587 else 00588 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00589 } 00590 else 00591 { 00592 if ($this->_haserrorfunctions) { 00593 $this->_errorMsg = ads_errormsg(); 00594 $this->_errorCode = ads_error(); 00595 } else 00596 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00597 } 00598 00599 return $stmtid; 00600 00601 } 00602 00603 /* 00604 Insert a null into the blob field of the table first. 00605 Then use UpdateBlob to store the blob. 00606 00607 Usage: 00608 00609 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 00610 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 00611 */ 00612 function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 00613 { 00614 $sql = "UPDATE $table SET $column=? WHERE $where"; 00615 $stmtid = ads_prepare($this->_connectionID,$sql); 00616 if ($stmtid == false){ 00617 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; 00618 return false; 00619 } 00620 if (! ads_execute($stmtid,array($val),array(SQL_BINARY) )){ 00621 if ($this->_haserrorfunctions){ 00622 $this->_errorMsg = ads_errormsg(); 00623 $this->_errorCode = ads_error(); 00624 } 00625 return false; 00626 } 00627 return TRUE; 00628 } 00629 00630 // returns true or false 00631 function _close() 00632 { 00633 $ret = @ads_close($this->_connectionID); 00634 $this->_connectionID = false; 00635 return $ret; 00636 } 00637 00638 function _affectedrows() 00639 { 00640 return $this->_lastAffectedRows; 00641 } 00642 00643 } 00644 00645 /*-------------------------------------------------------------------------------------- 00646 Class Name: Recordset 00647 --------------------------------------------------------------------------------------*/ 00648 00649 class ADORecordSet_ads extends ADORecordSet { 00650 00651 var $bind = false; 00652 var $databaseType = "ads"; 00653 var $dataProvider = "ads"; 00654 var $useFetchArray; 00655 var $_has_stupid_odbc_fetch_api_change; 00656 00657 function ADORecordSet_ads($id,$mode=false) 00658 { 00659 if ($mode === false) { 00660 global $ADODB_FETCH_MODE; 00661 $mode = $ADODB_FETCH_MODE; 00662 } 00663 $this->fetchMode = $mode; 00664 00665 $this->_queryID = $id; 00666 00667 // the following is required for mysql odbc driver in 4.3.1 -- why? 00668 $this->EOF = false; 00669 $this->_currentRow = -1; 00670 //$this->ADORecordSet($id); 00671 } 00672 00673 00674 // returns the field object 00675 function &FetchField($fieldOffset = -1) 00676 { 00677 00678 $off=$fieldOffset+1; // offsets begin at 1 00679 00680 $o= new ADOFieldObject(); 00681 $o->name = @ads_field_name($this->_queryID,$off); 00682 $o->type = @ads_field_type($this->_queryID,$off); 00683 $o->max_length = @ads_field_len($this->_queryID,$off); 00684 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 00685 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 00686 return $o; 00687 } 00688 00689 /* Use associative array to get fields array */ 00690 function Fields($colname) 00691 { 00692 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 00693 if (!$this->bind) { 00694 $this->bind = array(); 00695 for ($i=0; $i < $this->_numOfFields; $i++) { 00696 $o = $this->FetchField($i); 00697 $this->bind[strtoupper($o->name)] = $i; 00698 } 00699 } 00700 00701 return $this->fields[$this->bind[strtoupper($colname)]]; 00702 } 00703 00704 00705 function _initrs() 00706 { 00707 global $ADODB_COUNTRECS; 00708 $this->_numOfRows = ($ADODB_COUNTRECS) ? @ads_num_rows($this->_queryID) : -1; 00709 $this->_numOfFields = @ads_num_fields($this->_queryID); 00710 // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 00711 if ($this->_numOfRows == 0) $this->_numOfRows = -1; 00712 //$this->useFetchArray = $this->connection->useFetchArray; 00713 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; 00714 } 00715 00716 function _seek($row) 00717 { 00718 return false; 00719 } 00720 00721 // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated 00722 function &GetArrayLimit($nrows,$offset=-1) 00723 { 00724 if ($offset <= 0) { 00725 $rs =& $this->GetArray($nrows); 00726 return $rs; 00727 } 00728 $savem = $this->fetchMode; 00729 $this->fetchMode = ADODB_FETCH_NUM; 00730 $this->Move($offset); 00731 $this->fetchMode = $savem; 00732 00733 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00734 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00735 } 00736 00737 $results = array(); 00738 $cnt = 0; 00739 while (!$this->EOF && $nrows != $cnt) { 00740 $results[$cnt++] = $this->fields; 00741 $this->MoveNext(); 00742 } 00743 00744 return $results; 00745 } 00746 00747 00748 function MoveNext() 00749 { 00750 if ($this->_numOfRows != 0 && !$this->EOF) { 00751 $this->_currentRow++; 00752 00753 if ($this->_has_stupid_odbc_fetch_api_change) 00754 $rez = @ads_fetch_into($this->_queryID,$this->fields); 00755 else { 00756 $row = 0; 00757 $rez = @ads_fetch_into($this->_queryID,$row,$this->fields); 00758 } 00759 if ($rez) { 00760 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00761 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00762 } 00763 return true; 00764 } 00765 } 00766 $this->fields = false; 00767 $this->EOF = true; 00768 return false; 00769 } 00770 00771 function _fetch() 00772 { 00773 00774 if ($this->_has_stupid_odbc_fetch_api_change) 00775 $rez = @ads_fetch_into($this->_queryID,$this->fields); 00776 else { 00777 $row = 0; 00778 $rez = @ads_fetch_into($this->_queryID,$row,$this->fields); 00779 } 00780 if ($rez) { 00781 if ($this->fetchMode & ADODB_FETCH_ASSOC) { 00782 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); 00783 } 00784 return true; 00785 } 00786 $this->fields = false; 00787 return false; 00788 } 00789 00790 function _close() 00791 { 00792 return @ads_free_result($this->_queryID); 00793 } 00794 00795 } 00796 ?>