[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/adodb/drivers/ -> adodb-odbc.inc.php (source)

   1  <?php
   2  /*
   3  @version   v5.20.3  01-Jan-2016
   4  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   5  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   6    Released under both BSD license and Lesser GPL library license.
   7    Whenever there is any discrepancy between the two licenses,
   8    the BSD license will take precedence.
   9  Set tabs to 4 for best viewing.
  10  
  11    Latest version is available at http://adodb.sourceforge.net
  12  
  13    Requires ODBC. Works on Windows and Unix.
  14  */
  15  // security - hide paths
  16  if (!defined('ADODB_DIR')) die();
  17  
  18    define("_ADODB_ODBC_LAYER", 2 );
  19  
  20  /*--------------------------------------------------------------------------------------
  21  --------------------------------------------------------------------------------------*/
  22  
  23  
  24  class ADODB_odbc extends ADOConnection {
  25      var $databaseType = "odbc";
  26      var $fmtDate = "'Y-m-d'";
  27      var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  28      var $replaceQuote = "''"; // string to use to replace quotes
  29      var $dataProvider = "odbc";
  30      var $hasAffectedRows = true;
  31      var $binmode = ODBC_BINMODE_RETURN;
  32      var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive
  33                                  // breaking backward-compat
  34      //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
  35      var $_bindInputArray = false;
  36      var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
  37      var $_genSeqSQL = "create table %s (id integer)";
  38      var $_autocommit = true;
  39      var $_haserrorfunctions = true;
  40      var $_has_stupid_odbc_fetch_api_change = true;
  41      var $_lastAffectedRows = 0;
  42      var $uCaseTables = true; // for meta* functions, uppercase table names
  43  
  44  	function __construct()
  45      {
  46          $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;
  47          $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
  48      }
  49  
  50          // returns true or false
  51  	function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
  52      {
  53      global $php_errormsg;
  54  
  55          if (!function_exists('odbc_connect')) return null;
  56  
  57          if (!empty($argDatabasename) && stristr($argDSN, 'Database=') === false) {
  58              $argDSN = trim($argDSN);
  59              $endDSN = substr($argDSN, strlen($argDSN) - 1);
  60              if ($endDSN != ';') $argDSN .= ';';
  61              $argDSN .= 'Database='.$argDatabasename;
  62          }
  63  
  64          if (isset($php_errormsg)) $php_errormsg = '';
  65          if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  66          else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
  67          $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  68          if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  69  
  70          return $this->_connectionID != false;
  71      }
  72  
  73      // returns true or false
  74  	function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
  75      {
  76      global $php_errormsg;
  77  
  78          if (!function_exists('odbc_connect')) return null;
  79  
  80          if (isset($php_errormsg)) $php_errormsg = '';
  81          $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  82          if ($this->debug && $argDatabasename) {
  83              ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
  84          }
  85      //    print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
  86          if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  87          else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
  88  
  89          $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  90          if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
  91          if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  92  
  93          return $this->_connectionID != false;
  94      }
  95  
  96  
  97  	function ServerInfo()
  98      {
  99  
 100          if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
 101              $dsn = strtoupper($this->host);
 102              $first = true;
 103              $found = false;
 104  
 105              if (!function_exists('odbc_data_source')) return false;
 106  
 107              while(true) {
 108  
 109                  $rez = @odbc_data_source($this->_connectionID,
 110                      $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT);
 111                  $first = false;
 112                  if (!is_array($rez)) break;
 113                  if (strtoupper($rez['server']) == $dsn) {
 114                      $found = true;
 115                      break;
 116                  }
 117              }
 118              if (!$found) return ADOConnection::ServerInfo();
 119              if (!isset($rez['version'])) $rez['version'] = '';
 120              return $rez;
 121          } else {
 122              return ADOConnection::ServerInfo();
 123          }
 124      }
 125  
 126  
 127  	function CreateSequence($seqname='adodbseq',$start=1)
 128      {
 129          if (empty($this->_genSeqSQL)) return false;
 130          $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
 131          if (!$ok) return false;
 132          $start -= 1;
 133          return $this->Execute("insert into $seqname values($start)");
 134      }
 135  
 136      var $_dropSeqSQL = 'drop table %s';
 137  	function DropSequence($seqname = 'adodbseq')
 138      {
 139          if (empty($this->_dropSeqSQL)) return false;
 140          return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
 141      }
 142  
 143      /*
 144          This algorithm is not very efficient, but works even if table locking
 145          is not available.
 146  
 147          Will return false if unable to generate an ID after $MAXLOOPS attempts.
 148      */
 149  	function GenID($seq='adodbseq',$start=1)
 150      {
 151          // if you have to modify the parameter below, your database is overloaded,
 152          // or you need to implement generation of id's yourself!
 153          $MAXLOOPS = 100;
 154          //$this->debug=1;
 155          while (--$MAXLOOPS>=0) {
 156              $num = $this->GetOne("select id from $seq");
 157              if ($num === false) {
 158                  $this->Execute(sprintf($this->_genSeqSQL ,$seq));
 159                  $start -= 1;
 160                  $num = '0';
 161                  $ok = $this->Execute("insert into $seq values($start)");
 162                  if (!$ok) return false;
 163              }
 164              $this->Execute("update $seq set id=id+1 where id=$num");
 165  
 166              if ($this->affected_rows() > 0) {
 167                  $num += 1;
 168                  $this->genID = $num;
 169                  return $num;
 170              } elseif ($this->affected_rows() == 0) {
 171                  // some drivers do not return a valid value => try with another method
 172                  $value = $this->GetOne("select id from $seq");
 173                  if ($value == $num + 1) {
 174                      return $value;
 175                  }
 176              }
 177          }
 178          if ($fn = $this->raiseErrorFn) {
 179              $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
 180          }
 181          return false;
 182      }
 183  
 184  
 185  	function ErrorMsg()
 186      {
 187          if ($this->_haserrorfunctions) {
 188              if ($this->_errorMsg !== false) return $this->_errorMsg;
 189              if (empty($this->_connectionID)) return @odbc_errormsg();
 190              return @odbc_errormsg($this->_connectionID);
 191          } else return ADOConnection::ErrorMsg();
 192      }
 193  
 194  	function ErrorNo()
 195      {
 196  
 197          if ($this->_haserrorfunctions) {
 198              if ($this->_errorCode !== false) {
 199                  // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
 200                  return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode;
 201              }
 202  
 203              if (empty($this->_connectionID)) $e = @odbc_error();
 204              else $e = @odbc_error($this->_connectionID);
 205  
 206               // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
 207               // so we check and patch
 208              if (strlen($e)<=2) return 0;
 209              return $e;
 210          } else return ADOConnection::ErrorNo();
 211      }
 212  
 213  
 214  
 215  	function BeginTrans()
 216      {
 217          if (!$this->hasTransactions) return false;
 218          if ($this->transOff) return true;
 219          $this->transCnt += 1;
 220          $this->_autocommit = false;
 221          return odbc_autocommit($this->_connectionID,false);
 222      }
 223  
 224  	function CommitTrans($ok=true)
 225      {
 226          if ($this->transOff) return true;
 227          if (!$ok) return $this->RollbackTrans();
 228          if ($this->transCnt) $this->transCnt -= 1;
 229          $this->_autocommit = true;
 230          $ret = odbc_commit($this->_connectionID);
 231          odbc_autocommit($this->_connectionID,true);
 232          return $ret;
 233      }
 234  
 235  	function RollbackTrans()
 236      {
 237          if ($this->transOff) return true;
 238          if ($this->transCnt) $this->transCnt -= 1;
 239          $this->_autocommit = true;
 240          $ret = odbc_rollback($this->_connectionID);
 241          odbc_autocommit($this->_connectionID,true);
 242          return $ret;
 243      }
 244  
 245  	function MetaPrimaryKeys($table,$owner=false)
 246      {
 247      global $ADODB_FETCH_MODE;
 248  
 249          if ($this->uCaseTables) $table = strtoupper($table);
 250          $schema = '';
 251          $this->_findschema($table,$schema);
 252  
 253          $savem = $ADODB_FETCH_MODE;
 254          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 255          $qid = @odbc_primarykeys($this->_connectionID,'',$schema,$table);
 256  
 257          if (!$qid) {
 258              $ADODB_FETCH_MODE = $savem;
 259              return false;
 260          }
 261          $rs = new ADORecordSet_odbc($qid);
 262          $ADODB_FETCH_MODE = $savem;
 263  
 264          if (!$rs) return false;
 265          $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
 266  
 267          $arr = $rs->GetArray();
 268          $rs->Close();
 269          //print_r($arr);
 270          $arr2 = array();
 271          for ($i=0; $i < sizeof($arr); $i++) {
 272              if ($arr[$i][3]) $arr2[] = $arr[$i][3];
 273          }
 274          return $arr2;
 275      }
 276  
 277  
 278  
 279  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
 280      {
 281      global $ADODB_FETCH_MODE;
 282  
 283          $savem = $ADODB_FETCH_MODE;
 284          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 285          $qid = odbc_tables($this->_connectionID);
 286  
 287          $rs = new ADORecordSet_odbc($qid);
 288  
 289          $ADODB_FETCH_MODE = $savem;
 290          if (!$rs) {
 291              $false = false;
 292              return $false;
 293          }
 294          $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
 295  
 296          $arr = $rs->GetArray();
 297          //print_r($arr);
 298  
 299          $rs->Close();
 300          $arr2 = array();
 301  
 302          if ($ttype) {
 303              $isview = strncmp($ttype,'V',1) === 0;
 304          }
 305          for ($i=0; $i < sizeof($arr); $i++) {
 306              if (!$arr[$i][2]) continue;
 307              $type = $arr[$i][3];
 308              if ($ttype) {
 309                  if ($isview) {
 310                      if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
 311                  } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
 312              } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
 313          }
 314          return $arr2;
 315      }
 316  
 317  /*
 318  See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp
 319  / SQL data type codes /
 320  #define    SQL_UNKNOWN_TYPE    0
 321  #define SQL_CHAR            1
 322  #define SQL_NUMERIC         2
 323  #define SQL_DECIMAL         3
 324  #define SQL_INTEGER         4
 325  #define SQL_SMALLINT        5
 326  #define SQL_FLOAT           6
 327  #define SQL_REAL            7
 328  #define SQL_DOUBLE          8
 329  #if (ODBCVER >= 0x0300)
 330  #define SQL_DATETIME        9
 331  #endif
 332  #define SQL_VARCHAR        12
 333  
 334  
 335  / One-parameter shortcuts for date/time data types /
 336  #if (ODBCVER >= 0x0300)
 337  #define SQL_TYPE_DATE      91
 338  #define SQL_TYPE_TIME      92
 339  #define SQL_TYPE_TIMESTAMP 93
 340  
 341  #define SQL_UNICODE                             (-95)
 342  #define SQL_UNICODE_VARCHAR                     (-96)
 343  #define SQL_UNICODE_LONGVARCHAR                 (-97)
 344  */
 345  	function ODBCTypes($t)
 346      {
 347          switch ((integer)$t) {
 348          case 1:
 349          case 12:
 350          case 0:
 351          case -95:
 352          case -96:
 353              return 'C';
 354          case -97:
 355          case -1: //text
 356              return 'X';
 357          case -4: //image
 358              return 'B';
 359  
 360          case 9:
 361          case 91:
 362              return 'D';
 363  
 364          case 10:
 365          case 11:
 366          case 92:
 367          case 93:
 368              return 'T';
 369  
 370          case 4:
 371          case 5:
 372          case -6:
 373              return 'I';
 374  
 375          case -11: // uniqidentifier
 376              return 'R';
 377          case -7: //bit
 378              return 'L';
 379  
 380          default:
 381              return 'N';
 382          }
 383      }
 384  
 385  	function MetaColumns($table, $normalize=true)
 386      {
 387      global $ADODB_FETCH_MODE;
 388  
 389          $false = false;
 390          if ($this->uCaseTables) $table = strtoupper($table);
 391          $schema = '';
 392          $this->_findschema($table,$schema);
 393  
 394          $savem = $ADODB_FETCH_MODE;
 395          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 396  
 397          /*if (false) { // after testing, confirmed that the following does not work becoz of a bug
 398              $qid2 = odbc_tables($this->_connectionID);
 399              $rs = new ADORecordSet_odbc($qid2);
 400              $ADODB_FETCH_MODE = $savem;
 401              if (!$rs) return false;
 402              $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
 403              $rs->_fetch();
 404  
 405              while (!$rs->EOF) {
 406                  if ($table == strtoupper($rs->fields[2])) {
 407                      $q = $rs->fields[0];
 408                      $o = $rs->fields[1];
 409                      break;
 410                  }
 411                  $rs->MoveNext();
 412              }
 413              $rs->Close();
 414  
 415              $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
 416          } */
 417  
 418          switch ($this->databaseType) {
 419          case 'access':
 420          case 'vfp':
 421              $qid = odbc_columns($this->_connectionID);#,'%','',strtoupper($table),'%');
 422              break;
 423  
 424  
 425          case 'db2':
 426              $colname = "%";
 427              $qid = odbc_columns($this->_connectionID, "", $schema, $table, $colname);
 428              break;
 429  
 430          default:
 431              $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%');
 432              if (empty($qid)) $qid = odbc_columns($this->_connectionID);
 433              break;
 434          }
 435          if (empty($qid)) return $false;
 436  
 437          $rs = new ADORecordSet_odbc($qid);
 438          $ADODB_FETCH_MODE = $savem;
 439  
 440          if (!$rs) return $false;
 441          $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
 442          $rs->_fetch();
 443  
 444          $retarr = array();
 445  
 446          /*
 447          $rs->fields indices
 448          0 TABLE_QUALIFIER
 449          1 TABLE_SCHEM
 450          2 TABLE_NAME
 451          3 COLUMN_NAME
 452          4 DATA_TYPE
 453          5 TYPE_NAME
 454          6 PRECISION
 455          7 LENGTH
 456          8 SCALE
 457          9 RADIX
 458          10 NULLABLE
 459          11 REMARKS
 460          */
 461          while (!$rs->EOF) {
 462          //    adodb_pr($rs->fields);
 463              if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
 464                  $fld = new ADOFieldObject();
 465                  $fld->name = $rs->fields[3];
 466                  $fld->type = $this->ODBCTypes($rs->fields[4]);
 467  
 468                  // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
 469                  // access uses precision to store length for char/varchar
 470                  if ($fld->type == 'C' or $fld->type == 'X') {
 471                      if ($this->databaseType == 'access')
 472                          $fld->max_length = $rs->fields[6];
 473                      else if ($rs->fields[4] <= -95) // UNICODE
 474                          $fld->max_length = $rs->fields[7]/2;
 475                      else
 476                          $fld->max_length = $rs->fields[7];
 477                  } else
 478                      $fld->max_length = $rs->fields[7];
 479                  $fld->not_null = !empty($rs->fields[10]);
 480                  $fld->scale = $rs->fields[8];
 481                  $retarr[strtoupper($fld->name)] = $fld;
 482              } else if (sizeof($retarr)>0)
 483                  break;
 484              $rs->MoveNext();
 485          }
 486          $rs->Close(); //-- crashes 4.03pl1 -- why?
 487  
 488          if (empty($retarr)) $retarr = false;
 489          return $retarr;
 490      }
 491  
 492  	function Prepare($sql)
 493      {
 494          if (! $this->_bindInputArray) return $sql; // no binding
 495          $stmt = odbc_prepare($this->_connectionID,$sql);
 496          if (!$stmt) {
 497              // we don't know whether odbc driver is parsing prepared stmts, so just return sql
 498              return $sql;
 499          }
 500          return array($sql,$stmt,false);
 501      }
 502  
 503      /* returns queryID or false */
 504  	function _query($sql,$inputarr=false)
 505      {
 506      GLOBAL $php_errormsg;
 507          if (isset($php_errormsg)) $php_errormsg = '';
 508          $this->_error = '';
 509  
 510          if ($inputarr) {
 511              if (is_array($sql)) {
 512                  $stmtid = $sql[1];
 513              } else {
 514                  $stmtid = odbc_prepare($this->_connectionID,$sql);
 515  
 516                  if ($stmtid == false) {
 517                      $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
 518                      return false;
 519                  }
 520              }
 521  
 522              if (! odbc_execute($stmtid,$inputarr)) {
 523                  //@odbc_free_result($stmtid);
 524                  if ($this->_haserrorfunctions) {
 525                      $this->_errorMsg = odbc_errormsg();
 526                      $this->_errorCode = odbc_error();
 527                  }
 528                  return false;
 529              }
 530  
 531          } else if (is_array($sql)) {
 532              $stmtid = $sql[1];
 533              if (!odbc_execute($stmtid)) {
 534                  //@odbc_free_result($stmtid);
 535                  if ($this->_haserrorfunctions) {
 536                      $this->_errorMsg = odbc_errormsg();
 537                      $this->_errorCode = odbc_error();
 538                  }
 539                  return false;
 540              }
 541          } else
 542              $stmtid = odbc_exec($this->_connectionID,$sql);
 543  
 544          $this->_lastAffectedRows = 0;
 545          if ($stmtid) {
 546              if (@odbc_num_fields($stmtid) == 0) {
 547                  $this->_lastAffectedRows = odbc_num_rows($stmtid);
 548                  $stmtid = true;
 549              } else {
 550                  $this->_lastAffectedRows = 0;
 551                  odbc_binmode($stmtid,$this->binmode);
 552                  odbc_longreadlen($stmtid,$this->maxblobsize);
 553              }
 554  
 555              if ($this->_haserrorfunctions) {
 556                  $this->_errorMsg = '';
 557                  $this->_errorCode = 0;
 558              } else
 559                  $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
 560          } else {
 561              if ($this->_haserrorfunctions) {
 562                  $this->_errorMsg = odbc_errormsg();
 563                  $this->_errorCode = odbc_error();
 564              } else
 565                  $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
 566          }
 567          return $stmtid;
 568      }
 569  
 570      /*
 571          Insert a null into the blob field of the table first.
 572          Then use UpdateBlob to store the blob.
 573  
 574          Usage:
 575  
 576          $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
 577          $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
 578      */
 579  	function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
 580      {
 581          return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
 582      }
 583  
 584      // returns true or false
 585  	function _close()
 586      {
 587          $ret = @odbc_close($this->_connectionID);
 588          $this->_connectionID = false;
 589          return $ret;
 590      }
 591  
 592  	function _affectedrows()
 593      {
 594          return $this->_lastAffectedRows;
 595      }
 596  
 597  }
 598  
 599  /*--------------------------------------------------------------------------------------
 600       Class Name: Recordset
 601  --------------------------------------------------------------------------------------*/
 602  
 603  class ADORecordSet_odbc extends ADORecordSet {
 604  
 605      var $bind = false;
 606      var $databaseType = "odbc";
 607      var $dataProvider = "odbc";
 608      var $useFetchArray;
 609      var $_has_stupid_odbc_fetch_api_change;
 610  
 611  	function __construct($id,$mode=false)
 612      {
 613          if ($mode === false) {
 614              global $ADODB_FETCH_MODE;
 615              $mode = $ADODB_FETCH_MODE;
 616          }
 617          $this->fetchMode = $mode;
 618  
 619          $this->_queryID = $id;
 620  
 621          // the following is required for mysql odbc driver in 4.3.1 -- why?
 622          $this->EOF = false;
 623          $this->_currentRow = -1;
 624          //parent::__construct($id);
 625      }
 626  
 627  
 628      // returns the field object
 629  	function FetchField($fieldOffset = -1)
 630      {
 631  
 632          $off=$fieldOffset+1; // offsets begin at 1
 633  
 634          $o= new ADOFieldObject();
 635          $o->name = @odbc_field_name($this->_queryID,$off);
 636          $o->type = @odbc_field_type($this->_queryID,$off);
 637          $o->max_length = @odbc_field_len($this->_queryID,$off);
 638          if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
 639          else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
 640          return $o;
 641      }
 642  
 643      /* Use associative array to get fields array */
 644  	function Fields($colname)
 645      {
 646          if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
 647          if (!$this->bind) {
 648              $this->bind = array();
 649              for ($i=0; $i < $this->_numOfFields; $i++) {
 650                  $o = $this->FetchField($i);
 651                  $this->bind[strtoupper($o->name)] = $i;
 652              }
 653          }
 654  
 655           return $this->fields[$this->bind[strtoupper($colname)]];
 656      }
 657  
 658  
 659  	function _initrs()
 660      {
 661      global $ADODB_COUNTRECS;
 662          $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1;
 663          $this->_numOfFields = @odbc_num_fields($this->_queryID);
 664          // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
 665          if ($this->_numOfRows == 0) $this->_numOfRows = -1;
 666          //$this->useFetchArray = $this->connection->useFetchArray;
 667          $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
 668      }
 669  
 670  	function _seek($row)
 671      {
 672          return false;
 673      }
 674  
 675      // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
 676  	function GetArrayLimit($nrows,$offset=-1)
 677      {
 678          if ($offset <= 0) {
 679              $rs = $this->GetArray($nrows);
 680              return $rs;
 681          }
 682          $savem = $this->fetchMode;
 683          $this->fetchMode = ADODB_FETCH_NUM;
 684          $this->Move($offset);
 685          $this->fetchMode = $savem;
 686  
 687          if ($this->fetchMode & ADODB_FETCH_ASSOC) {
 688              $this->fields = $this->GetRowAssoc();
 689          }
 690  
 691          $results = array();
 692          $cnt = 0;
 693          while (!$this->EOF && $nrows != $cnt) {
 694              $results[$cnt++] = $this->fields;
 695              $this->MoveNext();
 696          }
 697  
 698          return $results;
 699      }
 700  
 701  
 702  	function MoveNext()
 703      {
 704          if ($this->_numOfRows != 0 && !$this->EOF) {
 705              $this->_currentRow++;
 706              if( $this->_fetch() ) {
 707                  return true;
 708              }
 709          }
 710          $this->fields = false;
 711          $this->EOF = true;
 712          return false;
 713      }
 714  
 715  	function _fetch()
 716      {
 717          $this->fields = false;
 718          if ($this->_has_stupid_odbc_fetch_api_change)
 719              $rez = @odbc_fetch_into($this->_queryID,$this->fields);
 720          else {
 721              $row = 0;
 722              $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
 723          }
 724          if ($rez) {
 725              if ($this->fetchMode & ADODB_FETCH_ASSOC) {
 726                  $this->fields = $this->GetRowAssoc();
 727              }
 728              return true;
 729          }
 730          return false;
 731      }
 732  
 733  	function _close()
 734      {
 735          return @odbc_free_result($this->_queryID);
 736      }
 737  
 738  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1