PHPOpenChat PHP Cross Reference Customer Relationship Management

Source: /include/adodb/drivers/adodb-pdo.inc.php - 688 lines - 20016 bytes - Summary - Text - Print

   1  <?php
   2  /* 

   3  V4.61 24 Feb 2005  (c) 2000-2005 John Lim (jlim#natsoft.com.my). All rights reserved.

   4    Released under both BSD license and Lesser GPL library license. 

   5    Whenever there is any discrepancy between the two licenses, 

   6    the BSD license will take precedence. 

   7  Set tabs to 4 for best viewing.

   8    

   9    Latest version is available at http://adodb.sourceforge.net

  10    

  11    Requires ODBC. Works on Windows and Unix.

  12  

  13      Problems: 

  14          Where is float/decimal type in pdo_param_type

  15          LOB handling for CLOB/BLOB differs significantly

  16  */
  17  // security - hide paths

  18  if (!defined('ADODB_DIR')) die();
  19  
  20  
  21  /*

  22  enum pdo_param_type {

  23  PDO_PARAM_NULL, 0

  24  

  25  /* int as in long (the php native int type).

  26   * If you mark a column as an int, PDO expects get_col to return

  27   * a pointer to a long 

  28  PDO_PARAM_INT, 1

  29  

  30  /* get_col ptr should point to start of the string buffer 

  31  PDO_PARAM_STR, 2

  32  

  33  /* get_col: when len is 0 ptr should point to a php_stream *,

  34   * otherwise it should behave like a string. Indicate a NULL field

  35   * value by setting the ptr to NULL 

  36  PDO_PARAM_LOB, 3

  37  

  38  /* get_col: will expect the ptr to point to a new PDOStatement object handle,

  39   * but this isn't wired up yet 

  40  PDO_PARAM_STMT, 4 /* hierarchical result set 

  41  

  42  /* get_col ptr should point to a zend_bool 

  43  PDO_PARAM_BOOL, 5

  44  

  45  

  46  /* magic flag to denote a parameter as being input/output 

  47  PDO_PARAM_INPUT_OUTPUT = 0x80000000

  48  };

  49  */
  50      
  51  function adodb_pdo_type($t)
  52  {
  53      switch($t) {
  54      case 2: return 'VARCHAR';
  55      case 3: return 'BLOB';
  56      default: return 'NUMERIC';
  57      }
  58  }
  59       
  60  /*--------------------------------------------------------------------------------------

  61  --------------------------------------------------------------------------------------*/
  62  
  63  
  64  class ADODB_pdo_pgsql extends ADODB_pdo {
  65  var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1";
  66      var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%'
  67      and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages',
  68       'sql_packages', 'sql_sizing', 'sql_sizing_profiles') 
  69      union 
  70          select viewname,'V' from pg_views where viewname not like 'pg\_%'";
  71      //"select tablename from pg_tables where tablename not like 'pg_%' order by 1";

  72      var $isoDates = true; // accepts dates in ISO format

  73      var $sysDate = "CURRENT_DATE";
  74      var $sysTimeStamp = "CURRENT_TIMESTAMP";
  75      var $blobEncodeType = 'C';
  76      var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum 
  77          FROM pg_class c, pg_attribute a,pg_type t 
  78          WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%'
  79  AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
  80  
  81      // used when schema defined

  82      var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum 
  83  FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n 
  84  WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s'))
  85   and c.relnamespace=n.oid and n.nspname='%s' 
  86      and a.attname not like '....%%' AND a.attnum > 0 
  87      AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
  88      
  89      // get primary key etc -- from Freek Dijkstra

  90      var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key 
  91      FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'";
  92      
  93      var $hasAffectedRows = true;
  94      var $hasLimit = false;    // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10

  95      // below suggested by Freek Dijkstra 

  96      var $true = 't';        // string that represents TRUE for a database

  97      var $false = 'f';        // string that represents FALSE for a database

  98      var $fmtDate = "'Y-m-d'";    // used by DBDate() as the default date format used by the database

  99      var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.

 100      var $hasMoveFirst = true;
 101      var $hasGenID = true;
 102      var $_genIDSQL = "SELECT NEXTVAL('%s')";
 103      var $_genSeqSQL = "CREATE SEQUENCE %s START %s";
 104      var $_dropSeqSQL = "DROP SEQUENCE %s";
 105      var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum";
 106      var $random = 'random()';        /// random function

 107      var $concat_operator='||';
 108       
 109  	function ServerInfo()
 110      {
 111          $arr['description'] = ADOConnection::GetOne("select version()");
 112          $arr['version'] = ADOConnection::_findvers($arr['description']);
 113          return $arr;
 114      }
 115      
 116      function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) 
 117      {
 118           $offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
 119           $limitStr  = ($nrows >= 0)  ? " LIMIT $nrows" : '';
 120           if ($secs2cache)
 121                $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
 122           else
 123                $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
 124          
 125          return $rs;
 126      }
 127      
 128      function &MetaTables($ttype=false,$showSchema=false,$mask=false) 
 129      {
 130          $info = $this->ServerInfo();
 131          if ($info['version'] >= 7.3) {
 132              $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%'
 133                and schemaname  not in ( 'pg_catalog','information_schema')
 134      union 
 135          select viewname,'V' from pg_views where viewname not like 'pg\_%'  and schemaname  not in ( 'pg_catalog','information_schema') ";
 136          }
 137          if ($mask) {
 138              $save = $this->metaTablesSQL;
 139              $mask = $this->qstr(strtolower($mask));
 140              if ($info['version']>=7.3)
 141                  $this->metaTablesSQL = "
 142  select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema')  
 143   union 
 144  select viewname,'V' from pg_views where viewname like $mask and schemaname  not in ( 'pg_catalog','information_schema')  ";
 145              else
 146                  $this->metaTablesSQL = "
 147  select tablename,'T' from pg_tables where tablename like $mask 
 148   union 
 149  select viewname,'V' from pg_views where viewname like $mask";
 150          }
 151          $ret =& ADOConnection::MetaTables($ttype,$showSchema);
 152          
 153          if ($mask) {
 154              $this->metaTablesSQL = $save;
 155          }
 156          return $ret;
 157      }
 158      
 159  function &MetaColumns($table,$normalize=true) 
 160      {
 161      global $ADODB_FETCH_MODE;
 162      
 163          $schema = false;
 164          $this->_findschema($table,$schema);
 165          
 166          if ($normalize) $table = strtolower($table);
 167  
 168          $save = $ADODB_FETCH_MODE;
 169          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 170          if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
 171          
 172          if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
 173          else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
 174          if (isset($savem)) $this->SetFetchMode($savem);
 175          $ADODB_FETCH_MODE = $save;
 176          
 177          if ($rs === false) {
 178              $false = false;
 179              return $false;
 180          }
 181          if (!empty($this->metaKeySQL)) {
 182              // If we want the primary keys, we have to issue a separate query

 183              // Of course, a modified version of the metaColumnsSQL query using a 

 184              // LEFT JOIN would have been much more elegant, but postgres does 

 185              // not support OUTER JOINS. So here is the clumsy way.

 186              
 187              $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 188              
 189              $rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
 190              // fetch all result in once for performance.

 191              $keys =& $rskey->GetArray();
 192              if (isset($savem)) $this->SetFetchMode($savem);
 193              $ADODB_FETCH_MODE = $save;
 194              
 195              $rskey->Close();
 196              unset($rskey);
 197          }
 198  
 199          $rsdefa = array();
 200          if (!empty($this->metaDefaultsSQL)) {
 201              $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 202              $sql = sprintf($this->metaDefaultsSQL, ($table));
 203              $rsdef = $this->Execute($sql);
 204              if (isset($savem)) $this->SetFetchMode($savem);
 205              $ADODB_FETCH_MODE = $save;
 206              
 207              if ($rsdef) {
 208                  while (!$rsdef->EOF) {
 209                      $num = $rsdef->fields['num'];
 210                      $s = $rsdef->fields['def'];
 211                      if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */
 212                          $s = substr($s, 1);
 213                          $s = substr($s, 0, strlen($s) - 1);
 214                      }
 215  
 216                      $rsdefa[$num] = $s;
 217                      $rsdef->MoveNext();
 218                  }
 219              } else {
 220                  ADOConnection::outp( "==> SQL => " . $sql);
 221              }
 222              unset($rsdef);
 223          }
 224      
 225          $retarr = array();
 226          while (!$rs->EOF) {     
 227              $fld = new ADOFieldObject();
 228              $fld->name = $rs->fields[0];
 229              $fld->type = $rs->fields[1];
 230              $fld->max_length = $rs->fields[2];
 231              if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4;
 232              if ($fld->max_length <= 0) $fld->max_length = -1;
 233              if ($fld->type == 'numeric') {
 234                  $fld->scale = $fld->max_length & 0xFFFF;
 235                  $fld->max_length >>= 16;
 236              }
 237              // dannym

 238              // 5 hasdefault; 6 num-of-column

 239              $fld->has_default = ($rs->fields[5] == 't');
 240              if ($fld->has_default) {
 241                  $fld->default_value = $rsdefa[$rs->fields[6]];
 242              }
 243  
 244              //Freek

 245              if ($rs->fields[4] == $this->true) {
 246                  $fld->not_null = true;
 247              }
 248              
 249              // Freek

 250              if (is_array($keys)) {
 251                  foreach($keys as $key) {
 252                      if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true) 
 253                          $fld->primary_key = true;
 254                      if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true) 
 255                          $fld->unique = true; // What name is more compatible?

 256                  }
 257              }
 258              
 259              if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;    
 260              else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld;
 261              
 262              $rs->MoveNext();
 263          }
 264          $rs->Close();
 265          return empty($retarr) ? false : $retarr;    
 266          
 267      }
 268  
 269  }
 270  
 271  class ADODB_pdo_base extends ADODB_pdo {
 272  
 273  	function ServerInfo()
 274      {
 275          return ADOConnection::ServerInfo();
 276      }
 277      
 278      function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
 279      {
 280          $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
 281          return $ret;
 282      }
 283      
 284  	function MetaTables()
 285      {
 286          return false;
 287      }
 288      
 289  	function MetaColumns()
 290      {
 291          return false;
 292      }
 293  }
 294  
 295  
 296  class ADODB_pdo extends ADOConnection {
 297      var $databaseType = "pdo";    
 298      var $dataProvider = "pdo";
 299      var $fmtDate = "'Y-m-d'";
 300      var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
 301      var $replaceQuote = "''"; // string to use to replace quotes

 302      var $hasAffectedRows = true;
 303      var $_bindInputArray = true;    
 304      var $_genSeqSQL = "create table %s (id integer)";
 305      var $_autocommit = true;
 306      var $_haserrorfunctions = true;
 307      var $_lastAffectedRows = 0;
 308      
 309      var $dsnType = '';
 310      var $stmt = false;
 311      
 312  	function ADODB_pdo()
 313      {
 314      }
 315      
 316  	function _UpdatePDO()
 317      {
 318          $d = &$this->_driver;
 319          $this->fmtDate = $d->fmtDate;
 320          $this->fmtTimeStamp = $d->fmtTimeStamp;
 321          $this->replaceQuote = $d->replaceQuote;
 322          $this->sysDate = $d->sysDate;
 323          $this->sysTimeStamp = $d->sysTimeStamp;
 324          $this->random = $d->random;
 325          $this->concat_operator = $d->concat_operator;
 326      }
 327      
 328  	function Time()
 329      {
 330          return false;
 331      }
 332      
 333      // returns true or false

 334  	function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist=false)
 335      {
 336          $at = strpos($argDSN,':');
 337          $this->dsnType = substr($argDSN,0,$at);
 338  
 339          $this->_connectionID = new PDO($argDSN, $argUsername, $argPassword);
 340          if ($this->_connectionID) {
 341              switch(ADODB_ASSOC_CASE){
 342              case 0: $m = PDO_CASE_LOWER; break;
 343              case 1: $m = PDO_CASE_UPPER; break;
 344              default:
 345              case 2: $m = PDO_CASE_NATURAL; break;
 346              }
 347              
 348              //$this->_connectionID->setAttribute(PDO_ATTR_ERRMODE,PDO_ERRMODE_SILENT );

 349              $this->_connectionID->setAttribute(PDO_ATTR_CASE,$m);
 350              
 351              $class = 'ADODB_pdo_'.$this->dsnType;
 352              //$this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true);

 353              if (class_exists($class))
 354                  $this->_driver = new $class();
 355              else
 356                  $this->_driver = new ADODB_pdo_base();
 357              
 358              $this->_driver->_connectionID = $this->_connectionID;
 359              $this->_UpdatePDO();
 360              return true;
 361          }
 362          $this->_driver = new ADODB_pdo_base();
 363          return false;
 364      }
 365      
 366      // returns true or false

 367  	function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
 368      {
 369          return $this->_connect($argDSN, $argUsername, $argPassword, $argDatabasename, true);
 370      }
 371      
 372      /*------------------------------------------------------------------------------*/

 373      
 374      
 375      function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) 
 376      {    
 377          $save = $this->_driver->fetchMode;
 378          $this->_driver->fetchMode = $this->fetchMode;
 379          $ret = $this->_driver->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
 380          $this->_driver->fetchMode = $save;
 381          return $ret;
 382      }
 383      
 384      
 385  	function ServerInfo()
 386      {
 387          return $this->_driver->ServerInfo();
 388      }
 389      
 390  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
 391      {
 392          return $this->_driver->MetaTables($ttype,$showSchema,$mask);
 393      }
 394      
 395  	function MetaColumns($table,$normalize=true)
 396      {
 397          return $this->_driver->MetaColumns($table,$normalize);
 398      }
 399      
 400  	function ErrorMsg()
 401      {
 402          if ($this->_stmt) $arr = $this->_stmt->errorInfo();
 403          else $arr = $this->_connectionID->errorInfo();
 404          
 405          if ($arr) {
 406              if ((integer)$arr[0]) return $arr[2];
 407              else return '';
 408          } else return '-1';
 409      }
 410      
 411  	function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
 412      {
 413          $obj = $stmt[1];
 414          if ($type) $obj->bindParam($name,$var,$type,$maxLen);
 415          else $obj->bindParam($name, $var);
 416      }
 417      
 418  	function ErrorNo()
 419      {
 420          if ($this->_stmt) $err = $this->_stmt->errorCode();
 421          else {
 422              $arr = $this->_connectionID->errorInfo();
 423              if (isset($arr[0])) $err = $arr[0];
 424              else $err = -1;
 425          }
 426          if ($err == '00000') return 0; // allows empty check

 427          return $err;
 428      }
 429  
 430  	function BeginTrans()
 431      {    
 432          if (!$this->hasTransactions) return false;
 433          if ($this->transOff) return true; 
 434          $this->transCnt += 1;
 435          $this->_autocommit = false;
 436          $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,false);
 437          return $this->_connectionID->beginTransaction();
 438      }
 439      
 440  	function CommitTrans($ok=true) 
 441      { 
 442          if (!$this->hasTransactions) return false;
 443          if ($this->transOff) return true; 
 444          if (!$ok) return $this->RollbackTrans();
 445          if ($this->transCnt) $this->transCnt -= 1;
 446          $this->_autocommit = true;
 447          
 448          $ret = $this->_connectionID->commit();
 449          $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true);
 450          return $ret;
 451      }
 452      
 453  	function RollbackTrans()
 454      {
 455          if (!$this->hasTransactions) return false;
 456          if ($this->transOff) return true; 
 457          if ($this->transCnt) $this->transCnt -= 1;
 458          $this->_autocommit = true;
 459          
 460          $ret = $this->_connectionID->rollback();
 461          $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true);
 462          return $ret;
 463      }
 464      
 465  	function Prepare($sql)
 466      {
 467          $this->_stmt = $this->_connectionID->prepare($sql);
 468          if ($this->_stmt) return array($sql,$this->_stmt);
 469          
 470          return false;
 471      }
 472      
 473  	function PrepareStmt($sql)
 474      {
 475          $stmt = $this->_connectionID->prepare($sql);
 476          if (!$stmt) return false;
 477          $obj = new ADOPDOStatement($stmt,$this);
 478          return $obj;
 479      }
 480  
 481      /* returns queryID or false */

 482  	function _query($sql,$inputarr=false) 
 483      {
 484          if (is_array($sql)) {
 485              $stmt = $sql[1];
 486          } else {
 487              $stmt = $this->_connectionID->prepare($sql);
 488          }
 489          if ($stmt) {
 490              if ($inputarr) $ok = $stmt->execute($inputarr);
 491              else $ok = $stmt->execute();
 492          }
 493          if ($ok) {
 494              $this->_stmt = $stmt;
 495              return $stmt;
 496          } 
 497          return false;
 498      }
 499  
 500      // returns true or false

 501  	function _close()
 502      {
 503          $this->_stmt = false;
 504          return true;
 505      }
 506  
 507  	function _affectedrows()
 508      {
 509          return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
 510      }
 511      
 512  	function _insertid()
 513      {
 514          return ($this->_connectionID) ? $this->_connectionID->lastInsertId() : 0;
 515      }
 516  }
 517  
 518  class ADOPDOStatement {
 519  
 520      var $databaseType = "pdo";        
 521      var $dataProvider = "pdo";
 522      var $_stmt;
 523      var $_connectionID;
 524      
 525  	function ADOPDOStatement($stmt,$connection)
 526      {
 527          $this->_stmt = $stmt;
 528          $this->_connectionID = $connection;
 529      }
 530      
 531  	function Execute($inputArr=false)
 532      {
 533          $savestmt = $this->_connectionID->_stmt;
 534          $rs = $this->_connectionID->Execute(array(false,$this->_stmt),$inputArr);
 535          $this->_connectionID->_stmt = $savestmt;
 536          return $rs;
 537      }
 538      
 539  	function InParameter(&$var,$name,$maxLen=4000,$type=false)
 540      {
 541  
 542          if ($type) $this->_stmt->bindParam($name,$var,$type,$maxLen);
 543          else $this->_stmt->bindParam($name, $var);
 544      }
 545      
 546  	function Affected_Rows()
 547      {
 548          return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
 549      }
 550      
 551  	function ErrorMsg()
 552      {
 553          if ($this->_stmt) $arr = $this->_stmt->errorInfo();
 554          else $arr = $this->_connectionID->errorInfo();
 555          print_r($arr);
 556          if (is_array($arr)) {
 557              if ((integer) $arr[0] && isset($arr[2])) return $arr[2];
 558              else return '';
 559          } else return '-1';
 560      }
 561      
 562  	function NumCols()
 563      {
 564          return ($this->_stmt) ? $this->_stmt->columnCount() : 0;
 565      }
 566      
 567  	function ErrorNo()
 568      {
 569          if ($this->_stmt) return $this->_stmt->errorCode();
 570          else return $this->_connectionID->errorInfo();
 571      }
 572  }
 573  
 574  /*--------------------------------------------------------------------------------------

 575       Class Name: Recordset

 576  --------------------------------------------------------------------------------------*/
 577  
 578  class ADORecordSet_pdo extends ADORecordSet {    
 579      
 580      var $bind = false;
 581      var $databaseType = "pdo";        
 582      var $dataProvider = "pdo";
 583      
 584  	function ADORecordSet_pdo($id,$mode=false)
 585      {
 586          if ($mode === false) {  
 587              global $ADODB_FETCH_MODE;
 588              $mode = $ADODB_FETCH_MODE;
 589          }
 590          $this->adodbFetchMode = $mode;
 591          switch($mode) {
 592          case ADODB_FETCH_NUM: $mode = PDO_FETCH_NUM; break;
 593          case ADODB_FETCH_ASSOC:  $mode = PDO_FETCH_ASSOC; break;
 594          
 595          case ADODB_FETCH_BOTH: 
 596          default: $mode = PDO_FETCH_BOTH; break;
 597          }
 598          $this->fetchMode = $mode;
 599          
 600          $this->_queryID = $id;
 601          $this->ADORecordSet($id);
 602      }
 603  
 604      
 605  	function Init()
 606      {
 607          if ($this->_inited) return;
 608          $this->_inited = true;
 609          if ($this->_queryID) @$this->_initrs();
 610          else {
 611              $this->_numOfRows = 0;
 612              $this->_numOfFields = 0;
 613          }
 614          if ($this->_numOfRows != 0 && $this->_currentRow == -1) {
 615              $this->_currentRow = 0;
 616              if ($this->EOF = ($this->_fetch() === false)) {
 617                  $this->_numOfRows = 0; // _numOfRows could be -1

 618              }
 619          } else {
 620              $this->EOF = true;
 621          }
 622      }
 623      
 624  	function _initrs()
 625      {
 626      global $ADODB_COUNTRECS;
 627      
 628          $this->_numOfRows = ($ADODB_COUNTRECS) ? @$this->_queryID->rowCount() : -1;
 629          if (!$this->_numOfRows) $this->_numOfRows = -1;
 630          $this->_numOfFields = $this->_queryID->columnCount();
 631      }
 632  
 633      // returns the field object

 634      function &FetchField($fieldOffset = -1) 
 635      {
 636          $off=$fieldOffset+1; // offsets begin at 1

 637          
 638          $o= new ADOFieldObject();
 639          $arr = $this->_queryID->getColumnMeta($fieldOffset);
 640          if (!$arr) return false;
 641  
 642          //adodb_pr($arr);

 643          $o->name = $arr['name'];
 644          if (isset($arr['native_type'])) $o->type = $arr['native_type'];
 645          else $o->type = adodb_pdo_type($arr['pdo_type']);
 646          $o->max_length = $arr['len'];
 647          $o->precision = $arr['precision'];
 648          
 649          if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
 650          else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
 651          return $o;
 652      }
 653      
 654  	function _seek($row)
 655      {
 656          return false;
 657      }
 658      
 659  	function _fetch()
 660      {
 661          if (!$this->_queryID) return false;
 662          
 663          $this->fields = $this->_queryID->fetch($this->fetchMode);
 664          return !empty($this->fields);
 665      }
 666      
 667  	function _close() 
 668      {
 669          $this->_queryID = false;
 670      }
 671      
 672  	function Fields($colname)
 673      {
 674          if ($this->adodbFetchMode != ADODB_FETCH_NUM) return @$this->fields[$colname];
 675          
 676          if (!$this->bind) {
 677              $this->bind = array();
 678              for ($i=0; $i < $this->_numOfFields; $i++) {
 679                  $o = $this->FetchField($i);
 680                  $this->bind[strtoupper($o->name)] = $i;
 681              }
 682          }
 683           return $this->fields[$this->bind[strtoupper($colname)]];
 684      }
 685  
 686  }
 687  
 688  ?>

title

Description

title

Description

title

Description

title

title

Body