C:/lib/adodb/adodb.inc.php Quellcode

adodb.inc.php
gehe zur Dokumentation dieser Datei
1 <?php
2 /*
3  * Set tabs to 4 for best viewing.
4  *
5  * Latest version is available at http://adodb.sourceforge.net
6  *
7  * This is the main include file for ADOdb.
8  * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php
9  *
10  * The ADOdb files are formatted so that doxygen can be used to generate documentation.
11  * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/
12  */
13 
35  if (!defined('_ADODB_LAYER')) {
36  define('_ADODB_LAYER',1);
37 
38  //==============================================================================================
39  // CONSTANT DEFINITIONS
40  //==============================================================================================
41 
42 
47  if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
48 
49  //==============================================================================================
50  // GLOBAL VARIABLES
51  //==============================================================================================
52 
53  GLOBAL
54  $ADODB_vers, // database version
55  $ADODB_COUNTRECS, // count number of records returned - slows down query
56  $ADODB_CACHE_DIR, // directory to cache recordsets
57  $ADODB_CACHE,
58  $ADODB_CACHE_CLASS,
59  $ADODB_EXTENSION, // ADODB extension installed
60  $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
61  $ADODB_FETCH_MODE, // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
62  $ADODB_GETONE_EOF,
63  $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.
64 
65  //==============================================================================================
66  // GLOBAL SETUP
67  //==============================================================================================
68 
69  $ADODB_EXTENSION = defined('ADODB_EXTENSION');
70 
71  //********************************************************//
72  /*
73  Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3).
74  Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi
75 
76  0 = ignore empty fields. All empty fields in array are ignored.
77  1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values.
78  2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values.
79  3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and empty fields '' are set to empty '' sql values.
80  */
81  define('ADODB_FORCE_IGNORE',0);
82  define('ADODB_FORCE_NULL',1);
83  define('ADODB_FORCE_EMPTY',2);
84  define('ADODB_FORCE_VALUE',3);
85  //********************************************************//
86 
87 
88  if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) {
89 
90  define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');
91 
92  // allow [ ] @ ` " and . in table names
93  define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)');
94 
95  // prefetching used by oracle
96  if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);
97 
98 
99  /*
100  Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.
101  This currently works only with mssql, odbc, oci8po and ibase derived drivers.
102 
103  0 = assoc lowercase field names. $rs->fields['orderid']
104  1 = assoc uppercase field names. $rs->fields['ORDERID']
105  2 = use native-case field names. $rs->fields['OrderID']
106  */
107  define('ADODB_ASSOC_CASE_LOWER', 0);
108  define('ADODB_ASSOC_CASE_UPPER', 1);
109  define('ADODB_ASSOC_CASE_NATIVE', 2);
110 
111  define('ADODB_FETCH_DEFAULT',0);
112  define('ADODB_FETCH_NUM',1);
113  define('ADODB_FETCH_ASSOC',2);
114  define('ADODB_FETCH_BOTH',3);
115 
116  if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);
117 
118  // PHP's version scheme makes converting to numbers difficult - workaround
119  $_adodb_ver = (float) PHP_VERSION;
120  if ($_adodb_ver >= 5.2) {
121  define('ADODB_PHPVER',0x5200);
122  } else if ($_adodb_ver >= 5.0) {
123  define('ADODB_PHPVER',0x5000);
124  } else
125  die("PHP5 or later required. You are running ".PHP_VERSION);
126  }
127 
128 
129  //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
130 
131 
135  function ADODB_str_replace($src, $dest, $data)
136  {
137  if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);
138 
139  $s = reset($src);
140  $d = reset($dest);
141  while ($s !== false) {
142  $data = str_replace($s,$d,$data);
143  $s = next($src);
144  $d = next($dest);
145  }
146  return $data;
147  }
148 
149  function ADODB_Setup()
150  {
151  GLOBAL
152  $ADODB_vers, // database version
153  $ADODB_COUNTRECS, // count number of records returned - slows down query
154  $ADODB_CACHE_DIR, // directory to cache recordsets
155  $ADODB_FETCH_MODE,
156  $ADODB_CACHE,
157  $ADODB_CACHE_CLASS,
158  $ADODB_FORCE_TYPE,
159  $ADODB_GETONE_EOF,
160  $ADODB_QUOTE_FIELDNAMES;
161 
162  if (empty($ADODB_CACHE_CLASS)) $ADODB_CACHE_CLASS = 'ADODB_Cache_File' ;
163  $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
164  $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;
165  $ADODB_GETONE_EOF = null;
166 
167  if (!isset($ADODB_CACHE_DIR)) {
168  $ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';
169  } else {
170  // do not accept url based paths, eg. http:/ or ftp:/
171  if (strpos($ADODB_CACHE_DIR,'://') !== false)
172  die("Illegal path http:// or ftp://");
173  }
174 
175 
176  // Initialize random number generator for randomizing cache flushes
177  // -- note Since PHP 4.2.0, the seed becomes optional and defaults to a random value if omitted.
178  srand(((double)microtime())*1000000);
179 
183  $ADODB_vers = 'V5.19dev ??-???-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved. Released BSD & LGPL.';
184 
190  if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true;
191  }
192 
193 
194  //==============================================================================================
195  // CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB
196  //==============================================================================================
197 
198  ADODB_Setup();
199 
200  //==============================================================================================
201  // CLASS ADOFieldObject
202  //==============================================================================================
206  class ADOFieldObject {
207  var $name = '';
208  var $max_length=0;
209  var $type="";
210 /*
211  // additional fields by dannym... (danny_milo@yahoo.com)
212  var $not_null = false;
213  // actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^
214  // so we can as well make not_null standard (leaving it at "false" does not harm anyways)
215 
216  var $has_default = false; // this one I have done only in mysql and postgres for now ...
217  // others to come (dannym)
218  var $default_value; // default, if any, and supported. Check has_default first.
219 */
220  }
221 
222 
223  function _adodb_safedate($s)
224  {
225  return str_replace(array("'", '\\'), '', $s);
226  }
227 
228  // parse date string to prevent injection attack
229  // date string will have one quote at beginning e.g. '3434343'
230  function _adodb_safedateq($s)
231  {
232  $len = strlen($s);
233  if ($s[0] !== "'") $s2 = "'".$s[0];
234  else $s2 = "'";
235  for($i=1; $i<$len; $i++) {
236  $ch = $s[$i];
237  if ($ch === '\\') {
238  $s2 .= "'";
239  break;
240  } elseif ($ch === "'") {
241  $s2 .= $ch;
242  break;
243  }
244 
245  $s2 .= $ch;
246  }
247 
248  return strlen($s2) == 0 ? 'null' : $s2;
249  }
250 
251 
252  // for transaction handling
253 
254  function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
255  {
256  //print "Errorno ($fn errno=$errno m=$errmsg) ";
257  $thisConnection->_transOK = false;
258  if ($thisConnection->_oldRaiseFn) {
259  $fn = $thisConnection->_oldRaiseFn;
260  $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection);
261  }
262  }
263 
264  //------------------
265  // class for caching
266  class ADODB_Cache_File {
267 
268  var $createdir = true; // requires creation of temp dirs
269 
270  function ADODB_Cache_File()
271  {
272  global $ADODB_INCLUDED_CSV;
273  if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
274  }
275 
276  // write serialised recordset to cache item/file
277  function writecache($filename, $contents, $debug, $secs2cache)
278  {
279  return adodb_write_file($filename, $contents,$debug);
280  }
281 
282  // load serialised recordset and unserialise it
283  function &readcache($filename, &$err, $secs2cache, $rsClass)
284  {
285  $rs = csv2rs($filename,$err,$secs2cache,$rsClass);
286  return $rs;
287  }
288 
289  // flush all items in cache
290  function flushall($debug=false)
291  {
292  global $ADODB_CACHE_DIR;
293 
294  $rez = false;
295 
296  if (strlen($ADODB_CACHE_DIR) > 1) {
297  $rez = $this->_dirFlush($ADODB_CACHE_DIR);
298  if ($debug) ADOConnection::outp( "flushall: $dir<br><pre>\n". $rez."</pre>");
299  }
300  return $rez;
301  }
302 
303  // flush one file in cache
304  function flushcache($f, $debug=false)
305  {
306  if (!@unlink($f)) {
307  if ($debug) ADOConnection::outp( "flushcache: failed for $f");
308  }
309  }
310 
311  function getdirname($hash)
312  {
313  global $ADODB_CACHE_DIR;
314  if (!isset($this->notSafeMode)) $this->notSafeMode = !ini_get('safe_mode');
315  return ($this->notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($hash,0,2) : $ADODB_CACHE_DIR;
316  }
317 
318  // create temp directories
319  function createdir($hash, $debug)
320  {
321  global $ADODB_CACHE_PERMS;
322 
323  $dir = $this->getdirname($hash);
324  if ($this->notSafeMode && !file_exists($dir)) {
325  $oldu = umask(0);
326  if (!@mkdir($dir, empty($ADODB_CACHE_PERMS) ? 0771 : $ADODB_CACHE_PERMS)) if(!is_dir($dir) && $debug) ADOConnection::outp("Cannot create $dir");
327  umask($oldu);
328  }
329 
330  return $dir;
331  }
332 
339  function _dirFlush($dir, $kill_top_level = false)
340  {
341  if(!$dh = @opendir($dir)) return;
342 
343  while (($obj = readdir($dh))) {
344  if($obj=='.' || $obj=='..') continue;
345  $f = $dir.'/'.$obj;
346 
347  if (strpos($obj,'.cache')) @unlink($f);
348  if (is_dir($f)) $this->_dirFlush($f, true);
349  }
350  if ($kill_top_level === true) @rmdir($dir);
351  return true;
352  }
353  }
354 
355  //==============================================================================================
356  // CLASS ADOConnection
357  //==============================================================================================
358 
362  class ADOConnection {
363  //
364  // PUBLIC VARS
365  //
366  var $dataProvider = 'native';
367  var $databaseType = '';
368  var $database = '';
369  var $host = '';
370  var $user = '';
371  var $password = '';
372  var $debug = false;
373  var $maxblobsize = 262144;
374  var $concat_operator = '+';
375  var $substr = 'substr';
376  var $length = 'length';
377  var $random = 'rand()';
378  var $upperCase = 'upper';
379  var $fmtDate = "'Y-m-d'";
380  var $fmtTimeStamp = "'Y-m-d, h:i:s A'";
381  var $true = '1';
382  var $false = '0';
383  var $replaceQuote = "\\'";
384  var $nameQuote = '"';
385  var $charSet=false;
386  var $metaDatabasesSQL = '';
387  var $metaTablesSQL = '';
388  var $uniqueOrderBy = false;
389  var $emptyDate = '&nbsp;';
390  var $emptyTimeStamp = '&nbsp;';
391  var $lastInsID = false;
392  //--
393  var $hasInsertID = false;
394  var $hasAffectedRows = false;
395  var $hasTop = false;
396  var $hasLimit = false;
397  var $readOnly = false;
398  var $hasMoveFirst = false;
399  var $hasGenID = false;
400  var $hasTransactions = true;
401  //--
402  var $genID = 0;
403  var $raiseErrorFn = false;
404  var $isoDates = false;
405  var $cacheSecs = 3600;
406 
407  // memcache
408  var $memCache = false;
409  var $memCacheHost;
410  var $memCachePort = 11211;
411  var $memCacheCompress = false;
412 
413  var $sysDate = false;
414  var $sysTimeStamp = false;
415  var $sysUTimeStamp = false; // name of function that returns the current timestamp accurate to the microsecond or nearest fraction
416  var $arrayClass = 'ADORecordSet_array';
417 
418  var $noNullStrings = false;
419  var $numCacheHits = 0;
420  var $numCacheMisses = 0;
421  var $pageExecuteCountRows = true;
422  var $uniqueSort = false;
423  var $leftOuter = false;
424  var $rightOuter = false;
425  var $ansiOuter = false;
426  var $autoRollback = false; // autoRollback on PConnect().
427  var $poorAffectedRows = false; // affectedRows not working or unreliable
428 
429  var $fnExecute = false;
430  var $fnCacheExecute = false;
431  var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char
432  var $rsPrefix = "ADORecordSet_";
433 
434  var $autoCommit = true;
435  var $transOff = 0;
436  var $transCnt = 0;
437 
438  var $fetchMode=false;
439 
440  var $null2null = 'null'; // in autoexecute/getinsertsql/getupdatesql, this value will be converted to a null
441  var $bulkBind = false; // enable 2D Execute array
442  //
443  // PRIVATE VARS
444  //
445  var $_oldRaiseFn = false;
446  var $_transOK = null;
447  var $_connectionID = false;
448  var $_errorMsg = false;
449  var $_errorCode = false;
451  var $_queryID = false;
452 
453  var $_isPersistentConnection = false;
454  var $_bindInputArray = false;
455  var $_evalAll = false;
456  var $_affected = false;
457  var $_logsql = false;
458  var $_transmode = ''; // transaction mode
459 
460 
461 
465  function ADOConnection()
466  {
467  die('Virtual Class -- cannot instantiate');
468  }
469 
470  static function Version()
471  {
472  global $ADODB_vers;
473 
474  $ok = preg_match( '/^[Vv]([0-9\.]+)/', $ADODB_vers, $matches );
475  if (!$ok) return (float) substr($ADODB_vers,1);
476  else return $matches[1];
477  }
478 
485  function ServerInfo()
486  {
487  return array('description' => '', 'version' => '');
488  }
489 
490  function IsConnected()
491  {
492  return !empty($this->_connectionID);
493  }
494 
495  function _findvers($str)
496  {
497  if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1];
498  else return '';
499  }
500 
505  static function outp($msg,$newline=true)
506  {
507  global $ADODB_FLUSH,$ADODB_OUTP;
508 
509  if (defined('ADODB_OUTP')) {
510  $fn = ADODB_OUTP;
511  $fn($msg,$newline);
512  return;
513  } else if (isset($ADODB_OUTP)) {
514  $fn = $ADODB_OUTP;
515  $fn($msg,$newline);
516  return;
517  }
518 
519  if ($newline) $msg .= "<br>\n";
520 
521  if (isset($_SERVER['HTTP_USER_AGENT']) || !$newline) echo $msg;
522  else echo strip_tags($msg);
523 
524 
525  if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); // do not flush if output buffering enabled - useless - thx to Jesse Mullan
526 
527  }
528 
529  function Time()
530  {
531  $rs = $this->_Execute("select $this->sysTimeStamp");
532  if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));
533 
534  return false;
535  }
536 
548  function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false)
549  {
550  if ($argHostname != "") $this->host = $argHostname;
551  if ($argUsername != "") $this->user = $argUsername;
552  if ($argPassword != "") $this->password = 'not stored'; // not stored for security reasons
553  if ($argDatabaseName != "") $this->database = $argDatabaseName;
554 
555  $this->_isPersistentConnection = false;
556 
557  if ($forceNew) {
558  if ($rez=$this->_nconnect($this->host, $this->user, $argPassword, $this->database)) return true;
559  } else {
560  if ($rez=$this->_connect($this->host, $this->user, $argPassword, $this->database)) return true;
561  }
562  if (isset($rez)) {
563  $err = $this->ErrorMsg();
564  if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";
565  $ret = false;
566  } else {
567  $err = "Missing extension for ".$this->dataProvider;
568  $ret = 0;
569  }
570  if ($fn = $this->raiseErrorFn)
571  $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
572 
573 
574  $this->_connectionID = false;
575  if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
576  return $ret;
577  }
578 
579  function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)
580  {
581  return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName);
582  }
583 
584 
595  function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
596  {
597  return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);
598  }
599 
610  function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
611  {
612 
613  if (defined('ADODB_NEVER_PERSIST'))
614  return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName);
615 
616  if ($argHostname != "") $this->host = $argHostname;
617  if ($argUsername != "") $this->user = $argUsername;
618  if ($argPassword != "") $this->password = 'not stored';
619  if ($argDatabaseName != "") $this->database = $argDatabaseName;
620 
621  $this->_isPersistentConnection = true;
622 
623  if ($rez = $this->_pconnect($this->host, $this->user, $argPassword, $this->database)) return true;
624  if (isset($rez)) {
625  $err = $this->ErrorMsg();
626  if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";
627  $ret = false;
628  } else {
629  $err = "Missing extension for ".$this->dataProvider;
630  $ret = 0;
631  }
632  if ($fn = $this->raiseErrorFn) {
633  $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
634  }
635 
636  $this->_connectionID = false;
637  if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
638  return $ret;
639  }
640 
641  function outp_throw($msg,$src='WARN',$sql='')
642  {
643  if (defined('ADODB_ERROR_HANDLER') && ADODB_ERROR_HANDLER == 'adodb_throw') {
644  adodb_throw($this->databaseType,$src,-9999,$msg,$sql,false,$this);
645  return;
646  }
647  ADOConnection::outp($msg);
648  }
649 
650  // create cache class. Code is backward compat with old memcache implementation
651  function _CreateCache()
652  {
653  global $ADODB_CACHE, $ADODB_CACHE_CLASS;
654 
655  if ($this->memCache) {
657 
658  if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');
659  $ADODB_CACHE = new ADODB_Cache_MemCache($this);
660  } else
661  $ADODB_CACHE = new $ADODB_CACHE_CLASS($this);
662 
663  }
664 
665  // Format date column in sql string given an input format that understands Y M D
666  function SQLDate($fmt, $col=false)
667  {
668  if (!$col) $col = $this->sysDate;
669  return $col; // child class implement
670  }
671 
687  function Prepare($sql)
688  {
689  return $sql;
690  }
691 
706  function PrepareSP($sql,$param=true)
707  {
708  return $this->Prepare($sql,$param);
709  }
710 
714  function Quote($s)
715  {
716  return $this->qstr($s,false);
717  }
718 
722  function QMagic($s)
723  {
724  return $this->qstr($s,get_magic_quotes_gpc());
725  }
726 
727  function q(&$s)
728  {
729  #if (!empty($this->qNull)) if ($s == 'null') return $s;
730  $s = $this->qstr($s,false);
731  }
732 
736  function ErrorNative()
737  {
738  return $this->ErrorNo();
739  }
740 
741 
745  function nextId($seq_name)
746  {
747  return $this->GenID($seq_name);
748  }
749 
757  function RowLock($table,$where,$col='1 as adodbignore')
758  {
759  return false;
760  }
761 
762  function CommitLock($table)
763  {
764  return $this->CommitTrans();
765  }
766 
767  function RollbackLock($table)
768  {
769  return $this->RollbackTrans();
770  }
771 
781  function SetFetchMode($mode)
782  {
783  $old = $this->fetchMode;
784  $this->fetchMode = $mode;
785 
786  if ($old === false) {
787  global $ADODB_FETCH_MODE;
788  return $ADODB_FETCH_MODE;
789  }
790  return $old;
791  }
792 
793 
797  function Query($sql, $inputarr=false)
798  {
799  $rs = $this->Execute($sql, $inputarr);
800  if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();
801  return $rs;
802  }
803 
804 
808  function LimitQuery($sql, $offset, $count, $params=false)
809  {
810  $rs = $this->SelectLimit($sql, $count, $offset, $params);
811  if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();
812  return $rs;
813  }
814 
815 
819  function Disconnect()
820  {
821  return $this->Close();
822  }
823 
824  /*
825  Returns placeholder for parameter, eg.
826  $DB->Param('a')
827 
828  will return ':a' for Oracle, and '?' for most other databases...
829 
830  For databases that require positioned params, eg $1, $2, $3 for postgresql,
831  pass in Param(false) before setting the first parameter.
832  */
833  function Param($name,$type='C')
834  {
835  return '?';
836  }
837 
838  /*
839  InParameter and OutParameter are self-documenting versions of Parameter().
840  */
841  function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
842  {
843  return $this->Parameter($stmt,$var,$name,false,$maxLen,$type);
844  }
845 
846  /*
847  */
848  function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
849  {
850  return $this->Parameter($stmt,$var,$name,true,$maxLen,$type);
851 
852  }
853 
854 
855  /*
856  Usage in oracle
857  $stmt = $db->Prepare('select * from table where id =:myid and group=:group');
858  $db->Parameter($stmt,$id,'myid');
859  $db->Parameter($stmt,$group,'group',64);
860  $db->Execute();
861 
862  @param $stmt Statement returned by Prepare() or PrepareSP().
863  @param $var PHP variable to bind to
864  @param $name Name of stored procedure variable name to bind to.
865  @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8.
866  @param [$maxLen] Holds an maximum length of the variable.
867  @param [$type] The data type of $var. Legal values depend on driver.
868 
869  */
870  function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)
871  {
872  return false;
873  }
874 
875 
876  function IgnoreErrors($saveErrs=false)
877  {
878  if (!$saveErrs) {
879  $saveErrs = array($this->raiseErrorFn,$this->_transOK);
880  $this->raiseErrorFn = false;
881  return $saveErrs;
882  } else {
883  $this->raiseErrorFn = $saveErrs[0];
884  $this->_transOK = $saveErrs[1];
885  }
886  }
887 
898  function StartTrans($errfn = 'ADODB_TransMonitor')
899  {
900  if ($this->transOff > 0) {
901  $this->transOff += 1;
902  return true;
903  }
904 
905  $this->_oldRaiseFn = $this->raiseErrorFn;
906  $this->raiseErrorFn = $errfn;
907  $this->_transOK = true;
908 
909  if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");
910  $ok = $this->BeginTrans();
911  $this->transOff = 1;
912  return $ok;
913  }
914 
915 
924  function CompleteTrans($autoComplete = true)
925  {
926  if ($this->transOff > 1) {
927  $this->transOff -= 1;
928  return true;
929  }
930  $this->raiseErrorFn = $this->_oldRaiseFn;
931 
932  $this->transOff = 0;
933  if ($this->_transOK && $autoComplete) {
934  if (!$this->CommitTrans()) {
935  $this->_transOK = false;
936  if ($this->debug) ADOConnection::outp("Smart Commit failed");
937  } else
938  if ($this->debug) ADOConnection::outp("Smart Commit occurred");
939  } else {
940  $this->_transOK = false;
941  $this->RollbackTrans();
942  if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred");
943  }
944 
945  return $this->_transOK;
946  }
947 
948  /*
949  At the end of a StartTrans/CompleteTrans block, perform a rollback.
950  */
951  function FailTrans()
952  {
953  if ($this->debug)
954  if ($this->transOff == 0) {
955  ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");
956  } else {
957  ADOConnection::outp("FailTrans was called");
958  adodb_backtrace();
959  }
960  $this->_transOK = false;
961  }
962 
966  function HasFailedTrans()
967  {
968  if ($this->transOff > 0) return $this->_transOK == false;
969  return false;
970  }
971 
979  function Execute($sql,$inputarr=false)
980  {
981  if ($this->fnExecute) {
982  $fn = $this->fnExecute;
983  $ret = $fn($this,$sql,$inputarr);
984  if (isset($ret)) return $ret;
985  }
986  if ($inputarr) {
987  if (!is_array($inputarr)) $inputarr = array($inputarr);
988 
989  $element0 = reset($inputarr);
990  # is_object check because oci8 descriptors can be passed in
991  $array_2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0));
992 
993  //remove extra memory copy of input -mikefedyk
994  unset($element0);
995 
996  if (!is_array($sql) && !$this->_bindInputArray) {
997  $sqlarr = explode('?',$sql);
998  $nparams = sizeof($sqlarr)-1;
999  if (!$array_2d) $inputarr = array($inputarr);
1000 
1001  foreach($inputarr as $arr) {
1002  $sql = ''; $i = 0;
1003  //Use each() instead of foreach to reduce memory usage -mikefedyk
1004  while(list(, $v) = each($arr)) {
1005  $sql .= $sqlarr[$i];
1006  // from Ron Baldwin <ron.baldwin#sourceprose.com>
1007  // Only quote string types
1008  $typ = gettype($v);
1009  if ($typ == 'string')
1010  //New memory copy of input created here -mikefedyk
1011  $sql .= $this->qstr($v);
1012  else if ($typ == 'double')
1013  $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
1014  else if ($typ == 'boolean')
1015  $sql .= $v ? $this->true : $this->false;
1016  else if ($typ == 'object') {
1017  if (method_exists($v, '__toString')) $sql .= $this->qstr($v->__toString());
1018  else $sql .= $this->qstr((string) $v);
1019  } else if ($v === null)
1020  $sql .= 'NULL';
1021  else
1022  $sql .= $v;
1023  $i += 1;
1024 
1025  if ($i == $nparams) break;
1026  } // while
1027  if (isset($sqlarr[$i])) {
1028  $sql .= $sqlarr[$i];
1029  if ($i+1 != sizeof($sqlarr)) $this->outp_throw( "Input Array does not match ?: ".htmlspecialchars($sql),'Execute');
1030  } else if ($i != sizeof($sqlarr))
1031  $this->outp_throw( "Input array does not match ?: ".htmlspecialchars($sql),'Execute');
1032 
1033  $ret = $this->_Execute($sql);
1034  if (!$ret) return $ret;
1035  }
1036  } else {
1037  if ($array_2d) {
1038  if (is_string($sql))
1039  $stmt = $this->Prepare($sql);
1040  else
1041  $stmt = $sql;
1042 
1043  foreach($inputarr as $arr) {
1044  $ret = $this->_Execute($stmt,$arr);
1045  if (!$ret) return $ret;
1046  }
1047  } else {
1048  $ret = $this->_Execute($sql,$inputarr);
1049  }
1050  }
1051  } else {
1052  $ret = $this->_Execute($sql,false);
1053  }
1054 
1055  return $ret;
1056  }
1057 
1058 
1059  function _Execute($sql,$inputarr=false)
1060  {
1061  if ($this->debug) {
1062  global $ADODB_INCLUDED_LIB;
1063  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
1064  $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);
1065  } else {
1066  $this->_queryID = @$this->_query($sql,$inputarr);
1067  }
1068 
1069  /************************
1070  // OK, query executed
1071  *************************/
1072 
1073  if ($this->_queryID === false) { // error handling if query fails
1074  if ($this->debug == 99) adodb_backtrace(true,5);
1075  $fn = $this->raiseErrorFn;
1076  if ($fn) {
1077  $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);
1078  }
1079  $false = false;
1080  return $false;
1081  }
1082 
1083  if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
1084  $rsclass = $this->rsPrefix.'empty';
1085  $rs = (class_exists($rsclass)) ? new $rsclass(): new ADORecordSet_empty();
1086 
1087  return $rs;
1088  }
1089 
1090  // return real recordset from select statement
1091  $rsclass = $this->rsPrefix.$this->databaseType;
1092  $rs = new $rsclass($this->_queryID,$this->fetchMode);
1093  $rs->connection = $this; // Pablo suggestion
1094  $rs->Init();
1095  if (is_array($sql)) $rs->sql = $sql[0];
1096  else $rs->sql = $sql;
1097  if ($rs->_numOfRows <= 0) {
1098  global $ADODB_COUNTRECS;
1099  if ($ADODB_COUNTRECS) {
1100  if (!$rs->EOF) {
1101  $rs = $this->_rs2rs($rs,-1,-1,!is_array($sql));
1102  $rs->_queryID = $this->_queryID;
1103  } else
1104  $rs->_numOfRows = 0;
1105  }
1106  }
1107  return $rs;
1108  }
1109 
1110  function CreateSequence($seqname='adodbseq',$startID=1)
1111  {
1112  if (empty($this->_genSeqSQL)) return false;
1113  return $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
1114  }
1115 
1116  function DropSequence($seqname='adodbseq')
1117  {
1118  if (empty($this->_dropSeqSQL)) return false;
1119  return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
1120  }
1121 
1130  function GenID($seqname='adodbseq',$startID=1)
1131  {
1132  if (!$this->hasGenID) {
1133  return 0; // formerly returns false pre 1.60
1134  }
1135 
1136  $getnext = sprintf($this->_genIDSQL,$seqname);
1137 
1138  $holdtransOK = $this->_transOK;
1139 
1140  $save_handler = $this->raiseErrorFn;
1141  $this->raiseErrorFn = '';
1142  @($rs = $this->Execute($getnext));
1143  $this->raiseErrorFn = $save_handler;
1144 
1145  if (!$rs) {
1146  $this->_transOK = $holdtransOK; //if the status was ok before reset
1147  $createseq = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
1148  $rs = $this->Execute($getnext);
1149  }
1150  if ($rs && !$rs->EOF) $this->genID = reset($rs->fields);
1151  else $this->genID = 0; // false
1152 
1153  if ($rs) $rs->Close();
1154 
1155  return $this->genID;
1156  }
1157 
1163  function Insert_ID($table='',$column='')
1164  {
1165  if ($this->_logsql && $this->lastInsID) return $this->lastInsID;
1166  if ($this->hasInsertID) return $this->_insertid($table,$column);
1167  if ($this->debug) {
1168  ADOConnection::outp( '<p>Insert_ID error</p>');
1169  adodb_backtrace();
1170  }
1171  return false;
1172  }
1173 
1174 
1181  function PO_Insert_ID($table="", $id="")
1182  {
1183  if ($this->hasInsertID){
1184  return $this->Insert_ID($table,$id);
1185  } else {
1186  return $this->GetOne("SELECT MAX($id) FROM $table");
1187  }
1188  }
1189 
1193  function Affected_Rows()
1194  {
1195  if ($this->hasAffectedRows) {
1196  if ($this->fnExecute === 'adodb_log_sql') {
1197  if ($this->_logsql && $this->_affected !== false) return $this->_affected;
1198  }
1199  $val = $this->_affectedrows();
1200  return ($val < 0) ? false : $val;
1201  }
1202 
1203  if ($this->debug) ADOConnection::outp( '<p>Affected_Rows error</p>',false);
1204  return false;
1205  }
1206 
1207 
1211  function ErrorMsg()
1212  {
1213  if ($this->_errorMsg) return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;
1214  else return '';
1215  }
1216 
1217 
1221  function ErrorNo()
1222  {
1223  return ($this->_errorMsg) ? -1 : 0;
1224  }
1225 
1226  function MetaError($err=false)
1227  {
1228  include_once(ADODB_DIR."/adodb-error.inc.php");
1229  if ($err === false) $err = $this->ErrorNo();
1230  return adodb_error($this->dataProvider,$this->databaseType,$err);
1231  }
1232 
1233  function MetaErrorMsg($errno)
1234  {
1235  include_once(ADODB_DIR."/adodb-error.inc.php");
1236  return adodb_errormsg($errno);
1237  }
1238 
1242  function MetaPrimaryKeys($table, $owner=false)
1243  {
1244  // owner not used in base class - see oci8
1245  $p = array();
1246  $objs = $this->MetaColumns($table);
1247  if ($objs) {
1248  foreach($objs as $v) {
1249  if (!empty($v->primary_key))
1250  $p[] = $v->name;
1251  }
1252  }
1253  if (sizeof($p)) return $p;
1254  if (function_exists('ADODB_VIEW_PRIMARYKEYS'))
1255  return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner);
1256  return false;
1257  }
1258 
1262  function MetaForeignKeys($table, $owner=false, $upper=false)
1263  {
1264  return false;
1265  }
1272  function SelectDB($dbName)
1273  {return false;}
1274 
1275 
1295  function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
1296  {
1297  if ($this->hasTop && $nrows > 0) {
1298  // suggested by Reinhard Balling. Access requires top after distinct
1299  // Informix requires first before distinct - F Riosa
1300  $ismssql = (strpos($this->databaseType,'mssql') !== false);
1301  if ($ismssql) $isaccess = false;
1302  else $isaccess = (strpos($this->databaseType,'access') !== false);
1303 
1304  if ($offset <= 0) {
1305 
1306  // access includes ties in result
1307  if ($isaccess) {
1308  $sql = preg_replace(
1309  '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
1310 
1311  if ($secs2cache != 0) {
1312  $ret = $this->CacheExecute($secs2cache, $sql,$inputarr);
1313  } else {
1314  $ret = $this->Execute($sql,$inputarr);
1315  }
1316  return $ret; // PHP5 fix
1317  } else if ($ismssql){
1318  $sql = preg_replace(
1319  '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
1320  } else {
1321  $sql = preg_replace(
1322  '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
1323  }
1324  } else {
1325  $nn = $nrows + $offset;
1326  if ($isaccess || $ismssql) {
1327  $sql = preg_replace(
1328  '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);
1329  } else {
1330  $sql = preg_replace(
1331  '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);
1332  }
1333  }
1334  }
1335 
1336  // if $offset>0, we want to skip rows, and $ADODB_COUNTRECS is set, we buffer rows
1337  // 0 to offset-1 which will be discarded anyway. So we disable $ADODB_COUNTRECS.
1338  global $ADODB_COUNTRECS;
1339 
1340  $savec = $ADODB_COUNTRECS;
1341  $ADODB_COUNTRECS = false;
1342 
1343 
1344  if ($secs2cache != 0) $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
1345  else $rs = $this->Execute($sql,$inputarr);
1346 
1347  $ADODB_COUNTRECS = $savec;
1348  if ($rs && !$rs->EOF) {
1349  $rs = $this->_rs2rs($rs,$nrows,$offset);
1350  }
1351  //print_r($rs);
1352  return $rs;
1353  }
1354 
1360  function SerializableRS(&$rs)
1361  {
1362  $rs2 = $this->_rs2rs($rs);
1363  $ignore = false;
1364  $rs2->connection = $ignore;
1365 
1366  return $rs2;
1367  }
1368 
1379  function &_rs2rs(&$rs,$nrows=-1,$offset=-1,$close=true)
1380  {
1381  if (! $rs) {
1382  $false = false;
1383  return $false;
1384  }
1385  $dbtype = $rs->databaseType;
1386  if (!$dbtype) {
1387  $rs = $rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ?
1388  return $rs;
1389  }
1390  if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) {
1391  $rs->MoveFirst();
1392  $rs = $rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ?
1393  return $rs;
1394  }
1395  $flds = array();
1396  for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
1397  $flds[] = $rs->FetchField($i);
1398  }
1399 
1400  $arr = $rs->GetArrayLimit($nrows,$offset);
1401  //print_r($arr);
1402  if ($close) $rs->Close();
1403 
1404  $arrayClass = $this->arrayClass;
1405 
1406  $rs2 = new $arrayClass();
1407  $rs2->connection = $this;
1408  $rs2->sql = $rs->sql;
1409  $rs2->dataProvider = $this->dataProvider;
1410  $rs2->InitArrayFields($arr,$flds);
1411  $rs2->fetchMode = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
1412  return $rs2;
1413  }
1414 
1415  /*
1416  * Return all rows. Compat with PEAR DB
1417  */
1418  function GetAll($sql, $inputarr=false)
1419  {
1420  $arr = $this->GetArray($sql,$inputarr);
1421  return $arr;
1422  }
1423 
1424  function GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)
1425  {
1426  $rs = $this->Execute($sql, $inputarr);
1427  if (!$rs) {
1428  $false = false;
1429  return $false;
1430  }
1431  $arr = $rs->GetAssoc($force_array,$first2cols);
1432  return $arr;
1433  }
1434 
1435  function CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false)
1436  {
1437  if (!is_numeric($secs2cache)) {
1438  $first2cols = $force_array;
1439  $force_array = $inputarr;
1440  }
1441  $rs = $this->CacheExecute($secs2cache, $sql, $inputarr);
1442  if (!$rs) {
1443  $false = false;
1444  return $false;
1445  }
1446  $arr = $rs->GetAssoc($force_array,$first2cols);
1447  return $arr;
1448  }
1449 
1457  function GetOne($sql,$inputarr=false)
1458  {
1459  global $ADODB_COUNTRECS,$ADODB_GETONE_EOF;
1460  $crecs = $ADODB_COUNTRECS;
1461  $ADODB_COUNTRECS = false;
1462 
1463  $ret = false;
1464  $rs = $this->Execute($sql,$inputarr);
1465  if ($rs) {
1466  if ($rs->EOF) $ret = $ADODB_GETONE_EOF;
1467  else $ret = reset($rs->fields);
1468 
1469  $rs->Close();
1470  }
1471  $ADODB_COUNTRECS = $crecs;
1472  return $ret;
1473  }
1474 
1475  // $where should include 'WHERE fld=value'
1476  function GetMedian($table, $field,$where = '')
1477  {
1478  $total = $this->GetOne("select count(*) from $table $where");
1479  if (!$total) return false;
1480 
1481  $midrow = (integer) ($total/2);
1482  $rs = $this->SelectLimit("select $field from $table $where order by 1",1,$midrow);
1483  if ($rs && !$rs->EOF) return reset($rs->fields);
1484  return false;
1485  }
1486 
1487 
1488  function CacheGetOne($secs2cache,$sql=false,$inputarr=false)
1489  {
1490  global $ADODB_GETONE_EOF;
1491  $ret = false;
1492  $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
1493  if ($rs) {
1494  if ($rs->EOF) $ret = $ADODB_GETONE_EOF;
1495  else $ret = reset($rs->fields);
1496  $rs->Close();
1497  }
1498 
1499  return $ret;
1500  }
1501 
1502  function GetCol($sql, $inputarr = false, $trim = false)
1503  {
1504 
1505  $rs = $this->Execute($sql, $inputarr);
1506  if ($rs) {
1507  $rv = array();
1508  if ($trim) {
1509  while (!$rs->EOF) {
1510  $rv[] = trim(reset($rs->fields));
1511  $rs->MoveNext();
1512  }
1513  } else {
1514  while (!$rs->EOF) {
1515  $rv[] = reset($rs->fields);
1516  $rs->MoveNext();
1517  }
1518  }
1519  $rs->Close();
1520  } else
1521  $rv = false;
1522  return $rv;
1523  }
1524 
1525  function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)
1526  {
1527  $rs = $this->CacheExecute($secs, $sql, $inputarr);
1528  if ($rs) {
1529  $rv = array();
1530  if ($trim) {
1531  while (!$rs->EOF) {
1532  $rv[] = trim(reset($rs->fields));
1533  $rs->MoveNext();
1534  }
1535  } else {
1536  while (!$rs->EOF) {
1537  $rv[] = reset($rs->fields);
1538  $rs->MoveNext();
1539  }
1540  }
1541  $rs->Close();
1542  } else
1543  $rv = false;
1544 
1545  return $rv;
1546  }
1547 
1548  function Transpose(&$rs,$addfieldnames=true)
1549  {
1550  $rs2 = $this->_rs2rs($rs);
1551  $false = false;
1552  if (!$rs2) return $false;
1553 
1554  $rs2->_transpose($addfieldnames);
1555  return $rs2;
1556  }
1557 
1558  /*
1559  Calculate the offset of a date for a particular database and generate
1560  appropriate SQL. Useful for calculating future/past dates and storing
1561  in a database.
1562 
1563  If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.
1564  */
1565  function OffsetDate($dayFraction,$date=false)
1566  {
1567  if (!$date) $date = $this->sysDate;
1568  return '('.$date.'+'.$dayFraction.')';
1569  }
1570 
1571 
1577  function GetArray($sql,$inputarr=false)
1578  {
1579  global $ADODB_COUNTRECS;
1580 
1581  $savec = $ADODB_COUNTRECS;
1582  $ADODB_COUNTRECS = false;
1583  $rs = $this->Execute($sql,$inputarr);
1584  $ADODB_COUNTRECS = $savec;
1585  if (!$rs)
1586  if (defined('ADODB_PEAR')) {
1587  $cls = ADODB_PEAR_Error();
1588  return $cls;
1589  } else {
1590  $false = false;
1591  return $false;
1592  }
1593  $arr = $rs->GetArray();
1594  $rs->Close();
1595  return $arr;
1596  }
1597 
1598  function CacheGetAll($secs2cache,$sql=false,$inputarr=false)
1599  {
1600  $arr = $this->CacheGetArray($secs2cache,$sql,$inputarr);
1601  return $arr;
1602  }
1603 
1604  function CacheGetArray($secs2cache,$sql=false,$inputarr=false)
1605  {
1606  global $ADODB_COUNTRECS;
1607 
1608  $savec = $ADODB_COUNTRECS;
1609  $ADODB_COUNTRECS = false;
1610  $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
1611  $ADODB_COUNTRECS = $savec;
1612 
1613  if (!$rs)
1614  if (defined('ADODB_PEAR')) {
1615  $cls = ADODB_PEAR_Error();
1616  return $cls;
1617  } else {
1618  $false = false;
1619  return $false;
1620  }
1621  $arr = $rs->GetArray();
1622  $rs->Close();
1623  return $arr;
1624  }
1625 
1626  function GetRandRow($sql, $arr= false)
1627  {
1628  $rezarr = $this->GetAll($sql, $arr);
1629  $sz = sizeof($rezarr);
1630  return $rezarr[abs(rand()) % $sz];
1631  }
1632 
1640  function GetRow($sql,$inputarr=false)
1641  {
1642  global $ADODB_COUNTRECS;
1643  $crecs = $ADODB_COUNTRECS;
1644  $ADODB_COUNTRECS = false;
1645 
1646  $rs = $this->Execute($sql,$inputarr);
1647 
1648  $ADODB_COUNTRECS = $crecs;
1649  if ($rs) {
1650  if (!$rs->EOF) $arr = $rs->fields;
1651  else $arr = array();
1652  $rs->Close();
1653  return $arr;
1654  }
1655 
1656  $false = false;
1657  return $false;
1658  }
1659 
1660  function CacheGetRow($secs2cache,$sql=false,$inputarr=false)
1661  {
1662  $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
1663  if ($rs) {
1664  if (!$rs->EOF) $arr = $rs->fields;
1665  else $arr = array();
1666 
1667  $rs->Close();
1668  return $arr;
1669  }
1670  $false = false;
1671  return $false;
1672  }
1673 
1694  function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false)
1695  {
1696  global $ADODB_INCLUDED_LIB;
1697  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
1698 
1699  return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc);
1700  }
1701 
1702 
1721  function CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false)
1722  {
1723  if (!is_numeric($secs2cache)) {
1724  if ($sql === false) $sql = -1;
1725  if ($offset == -1) $offset = false;
1726  // sql, nrows, offset,inputarr
1727  $rs = $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs);
1728  } else {
1729  if ($sql === false) $this->outp_throw("Warning: \$sql missing from CacheSelectLimit()",'CacheSelectLimit');
1730  $rs = $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
1731  }
1732  return $rs;
1733  }
1734 
1735 
1745  function CacheFlush($sql=false,$inputarr=false)
1746  {
1747  global $ADODB_CACHE_DIR, $ADODB_CACHE;
1748 
1749  if (empty($ADODB_CACHE)) return false;
1750 
1751  if (!$sql) {
1752  $ADODB_CACHE->flushall($this->debug);
1753  return;
1754  }
1755 
1756  $f = $this->_gencachename($sql.serialize($inputarr),false);
1757  return $ADODB_CACHE->flushcache($f, $this->debug);
1758  }
1759 
1760 
1775  function _gencachename($sql,$createdir)
1776  {
1777  global $ADODB_CACHE, $ADODB_CACHE_DIR;
1778 
1779  if ($this->fetchMode === false) {
1780  global $ADODB_FETCH_MODE;
1781  $mode = $ADODB_FETCH_MODE;
1782  } else {
1783  $mode = $this->fetchMode;
1784  }
1785  $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode);
1786  if (!$ADODB_CACHE->createdir) return $m;
1787  if (!$createdir) $dir = $ADODB_CACHE->getdirname($m);
1788  else $dir = $ADODB_CACHE->createdir($m, $this->debug);
1789 
1790  return $dir.'/adodb_'.$m.'.cache';
1791  }
1792 
1793 
1803  function CacheExecute($secs2cache,$sql=false,$inputarr=false)
1804  {
1805  global $ADODB_CACHE;
1806 
1807  if (empty($ADODB_CACHE)) $this->_CreateCache();
1808 
1809  if (!is_numeric($secs2cache)) {
1810  $inputarr = $sql;
1811  $sql = $secs2cache;
1812  $secs2cache = $this->cacheSecs;
1813  }
1814 
1815  if (is_array($sql)) {
1816  $sqlparam = $sql;
1817  $sql = $sql[0];
1818  } else
1819  $sqlparam = $sql;
1820 
1821 
1822  $md5file = $this->_gencachename($sql.serialize($inputarr),true);
1823  $err = '';
1824 
1825  if ($secs2cache > 0){
1826  $rs = $ADODB_CACHE->readcache($md5file,$err,$secs2cache,$this->arrayClass);
1827  $this->numCacheHits += 1;
1828  } else {
1829  $err='Timeout 1';
1830  $rs = false;
1831  $this->numCacheMisses += 1;
1832  }
1833 
1834  if (!$rs) {
1835  // no cached rs found
1836  if ($this->debug) {
1837  if (get_magic_quotes_runtime() && !$this->memCache) {
1838  ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");
1839  }
1840  if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (this is a notice and not an error)");
1841  }
1842 
1843  $rs = $this->Execute($sqlparam,$inputarr);
1844 
1845  if ($rs) {
1846 
1847  $eof = $rs->EOF;
1848  $rs = $this->_rs2rs($rs); // read entire recordset into memory immediately
1849  $rs->timeCreated = time(); // used by caching
1850  $txt = _rs2serialize($rs,false,$sql); // serialize
1851 
1852  $ok = $ADODB_CACHE->writecache($md5file,$txt,$this->debug, $secs2cache);
1853  if (!$ok) {
1854  if ($ok === false) {
1855  $em = 'Cache write error';
1856  $en = -32000;
1857 
1858  if ($fn = $this->raiseErrorFn) {
1859  $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this);
1860  }
1861  } else {
1862  $em = 'Cache file locked warning';
1863  $en = -32001;
1864  // do not call error handling for just a warning
1865  }
1866 
1867  if ($this->debug) ADOConnection::outp( " ".$em);
1868  }
1869  if ($rs->EOF && !$eof) {
1870  $rs->MoveFirst();
1871  //$rs = csv2rs($md5file,$err);
1872  $rs->connection = $this; // Pablo suggestion
1873  }
1874 
1875  } else if (!$this->memCache)
1876  $ADODB_CACHE->flushcache($md5file);
1877  } else {
1878  $this->_errorMsg = '';
1879  $this->_errorCode = 0;
1880 
1881  if ($this->fnCacheExecute) {
1882  $fn = $this->fnCacheExecute;
1883  $fn($this, $secs2cache, $sql, $inputarr);
1884  }
1885  // ok, set cached object found
1886  $rs->connection = $this; // Pablo suggestion
1887  if ($this->debug){
1888  if ($this->debug == 99) adodb_backtrace();
1889  $inBrowser = isset($_SERVER['HTTP_USER_AGENT']);
1890  $ttl = $rs->timeCreated + $secs2cache - time();
1891  $s = is_array($sql) ? $sql[0] : $sql;
1892  if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>';
1893 
1894  ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]");
1895  }
1896  }
1897  return $rs;
1898  }
1899 
1900 
1901  /*
1902  Similar to PEAR DB's autoExecute(), except that
1903  $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
1904  If $mode == 'UPDATE', then $where is compulsory as a safety measure.
1905 
1906  $forceUpdate means that even if the data has not changed, perform update.
1907  */
1908  function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)
1909  {
1910  $false = false;
1911  $sql = 'SELECT * FROM '.$table;
1912  if ($where!==FALSE) $sql .= ' WHERE '.$where;
1913  else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) {
1914  $this->outp_throw('AutoExecute: Illegal mode=UPDATE with empty WHERE clause','AutoExecute');
1915  return $false;
1916  }
1917 
1918  $rs = $this->SelectLimit($sql,1);
1919  if (!$rs) return $false; // table does not exist
1920  $rs->tableName = $table;
1921  $rs->sql = $sql;
1922 
1923  switch((string) $mode) {
1924  case 'UPDATE':
1925  case '2':
1926  $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq);
1927  break;
1928  case 'INSERT':
1929  case '1':
1930  $sql = $this->GetInsertSQL($rs, $fields_values, $magicq);
1931  break;
1932  default:
1933  $this->outp_throw("AutoExecute: Unknown mode=$mode",'AutoExecute');
1934  return $false;
1935  }
1936  $ret = false;
1937  if ($sql) $ret = $this->Execute($sql);
1938  if ($ret) $ret = true;
1939  return $ret;
1940  }
1941 
1942 
1954  function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null)
1955  {
1956  global $ADODB_INCLUDED_LIB;
1957 
1958  //********************************************************//
1959  //This is here to maintain compatibility
1960  //with older adodb versions. Sets force type to force nulls if $forcenulls is set.
1961  if (!isset($force)) {
1962  global $ADODB_FORCE_TYPE;
1963  $force = $ADODB_FORCE_TYPE;
1964  }
1965  //********************************************************//
1966 
1967  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
1968  return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force);
1969  }
1970 
1979  function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null)
1980  {
1981  global $ADODB_INCLUDED_LIB;
1982  if (!isset($force)) {
1983  global $ADODB_FORCE_TYPE;
1984  $force = $ADODB_FORCE_TYPE;
1985 
1986  }
1987  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
1988  return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force);
1989  }
1990 
1991 
2011  function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
2012  {
2013  return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
2014  }
2015 
2025  function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')
2026  {
2027  $fd = fopen($path,'rb');
2028  if ($fd === false) return false;
2029  $val = fread($fd,filesize($path));
2030  fclose($fd);
2031  return $this->UpdateBlob($table,$column,$val,$where,$blobtype);
2032  }
2033 
2034  function BlobDecode($blob)
2035  {
2036  return $blob;
2037  }
2038 
2039  function BlobEncode($blob)
2040  {
2041  return $blob;
2042  }
2043 
2044  function SetCharSet($charset)
2045  {
2046  return false;
2047  }
2048 
2049  function IfNull( $field, $ifNull )
2050  {
2051  return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
2052  }
2053 
2054  function LogSQL($enable=true)
2055  {
2056  include_once(ADODB_DIR.'/adodb-perf.inc.php');
2057 
2058  if ($enable) $this->fnExecute = 'adodb_log_sql';
2059  else $this->fnExecute = false;
2060 
2061  $old = $this->_logsql;
2062  $this->_logsql = $enable;
2063  if ($enable && !$old) $this->_affected = false;
2064  return $old;
2065  }
2066 
2067  function GetCharSet()
2068  {
2069  return false;
2070  }
2071 
2079  function UpdateClob($table,$column,$val,$where)
2080  {
2081  return $this->UpdateBlob($table,$column,$val,$where,'CLOB');
2082  }
2083 
2084  // not the fastest implementation - quick and dirty - jlim
2085  // for best performance, use the actual $rs->MetaType().
2086  function MetaType($t,$len=-1,$fieldobj=false)
2087  {
2088 
2089  if (empty($this->_metars)) {
2090  $rsclass = $this->rsPrefix.$this->databaseType;
2091  $this->_metars = new $rsclass(false,$this->fetchMode);
2092  $this->_metars->connection = $this;
2093  }
2094  return $this->_metars->MetaType($t,$len,$fieldobj);
2095  }
2096 
2097 
2102  function SetDateLocale($locale = 'En')
2103  {
2104  $this->locale = $locale;
2105  switch (strtoupper($locale))
2106  {
2107  case 'EN':
2108  $this->fmtDate="'Y-m-d'";
2109  $this->fmtTimeStamp = "'Y-m-d H:i:s'";
2110  break;
2111 
2112  case 'US':
2113  $this->fmtDate = "'m-d-Y'";
2114  $this->fmtTimeStamp = "'m-d-Y H:i:s'";
2115  break;
2116 
2117  case 'PT_BR':
2118  case 'NL':
2119  case 'FR':
2120  case 'RO':
2121  case 'IT':
2122  $this->fmtDate="'d-m-Y'";
2123  $this->fmtTimeStamp = "'d-m-Y H:i:s'";
2124  break;
2125 
2126  case 'GE':
2127  $this->fmtDate="'d.m.Y'";
2128  $this->fmtTimeStamp = "'d.m.Y H:i:s'";
2129  break;
2130 
2131  default:
2132  $this->fmtDate="'Y-m-d'";
2133  $this->fmtTimeStamp = "'Y-m-d H:i:s'";
2134  break;
2135  }
2136  }
2137 
2151  function GetActiveRecordsClass(
2152  $class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false,
2153  $extra=array(),
2154  $relations=array())
2155  {
2156  global $_ADODB_ACTIVE_DBS;
2157  ## reduce overhead of adodb.inc.php -- moved to adodb-active-record.inc.php
2158  ## if adodb-active-recordx is loaded -- should be no issue as they will probably use Find()
2159  if (!isset($_ADODB_ACTIVE_DBS))include_once(ADODB_DIR.'/adodb-active-record.inc.php');
2160  return adodb_GetActiveRecordsClass($this, $class, $table, $whereOrderBy, $bindarr, $primkeyArr, $extra, $relations);
2161  }
2162 
2163  function GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false)
2164  {
2165  $arr = $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr);
2166  return $arr;
2167  }
2168 
2172  function Close()
2173  {
2174  $rez = $this->_close();
2175  $this->_connectionID = false;
2176  return $rez;
2177  }
2178 
2184  function BeginTrans()
2185  {
2186  if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver");
2187  return false;
2188  }
2189 
2190  /* set transaction mode */
2191  function SetTransactionMode( $transaction_mode )
2192  {
2193  $transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider);
2194  $this->_transmode = $transaction_mode;
2195  }
2196 /*
2197 http://msdn2.microsoft.com/en-US/ms173763.aspx
2198 http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-isolation.html
2199 http://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.html
2200 http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm
2201 */
2202  function MetaTransaction($mode,$db)
2203  {
2204  $mode = strtoupper($mode);
2205  $mode = str_replace('ISOLATION LEVEL ','',$mode);
2206 
2207  switch($mode) {
2208 
2209  case 'READ UNCOMMITTED':
2210  switch($db) {
2211  case 'oci8':
2212  case 'oracle':
2213  return 'ISOLATION LEVEL READ COMMITTED';
2214  default:
2215  return 'ISOLATION LEVEL READ UNCOMMITTED';
2216  }
2217  break;
2218 
2219  case 'READ COMMITTED':
2220  return 'ISOLATION LEVEL READ COMMITTED';
2221  break;
2222 
2223  case 'REPEATABLE READ':
2224  switch($db) {
2225  case 'oci8':
2226  case 'oracle':
2227  return 'ISOLATION LEVEL SERIALIZABLE';
2228  default:
2229  return 'ISOLATION LEVEL REPEATABLE READ';
2230  }
2231  break;
2232 
2233  case 'SERIALIZABLE':
2234  return 'ISOLATION LEVEL SERIALIZABLE';
2235  break;
2236 
2237  default:
2238  return $mode;
2239  }
2240  }
2241 
2249  function CommitTrans($ok=true)
2250  { return true;}
2251 
2252 
2258  function RollbackTrans()
2259  { return false;}
2260 
2261 
2268  function MetaDatabases()
2269  {
2270  global $ADODB_FETCH_MODE;
2271 
2272  if ($this->metaDatabasesSQL) {
2273  $save = $ADODB_FETCH_MODE;
2274  $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
2275 
2276  if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
2277 
2278  $arr = $this->GetCol($this->metaDatabasesSQL);
2279  if (isset($savem)) $this->SetFetchMode($savem);
2280  $ADODB_FETCH_MODE = $save;
2281 
2282  return $arr;
2283  }
2284 
2285  return false;
2286  }
2287 
2306  function MetaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null)
2307  {
2308  return false;
2309  }
2310 
2311 
2322  function MetaTables($ttype=false,$showSchema=false,$mask=false)
2323  {
2324  global $ADODB_FETCH_MODE;
2325 
2326 
2327  $false = false;
2328  if ($mask) {
2329  return $false;
2330  }
2331  if ($this->metaTablesSQL) {
2332  $save = $ADODB_FETCH_MODE;
2333  $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
2334 
2335  if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
2336 
2337  $rs = $this->Execute($this->metaTablesSQL);
2338  if (isset($savem)) $this->SetFetchMode($savem);
2339  $ADODB_FETCH_MODE = $save;
2340 
2341  if ($rs === false) return $false;
2342  $arr = $rs->GetArray();
2343  $arr2 = array();
2344 
2345  if ($hast = ($ttype && isset($arr[0][1]))) {
2346  $showt = strncmp($ttype,'T',1);
2347  }
2348 
2349  for ($i=0; $i < sizeof($arr); $i++) {
2350  if ($hast) {
2351  if ($showt == 0) {
2352  if (strncmp($arr[$i][1],'T',1) == 0) $arr2[] = trim($arr[$i][0]);
2353  } else {
2354  if (strncmp($arr[$i][1],'V',1) == 0) $arr2[] = trim($arr[$i][0]);
2355  }
2356  } else
2357  $arr2[] = trim($arr[$i][0]);
2358  }
2359  $rs->Close();
2360  return $arr2;
2361  }
2362  return $false;
2363  }
2364 
2365 
2366  function _findschema(&$table,&$schema)
2367  {
2368  if (!$schema && ($at = strpos($table,'.')) !== false) {
2369  $schema = substr($table,0,$at);
2370  $table = substr($table,$at+1);
2371  }
2372  }
2373 
2384  function MetaColumns($table,$normalize=true)
2385  {
2386  global $ADODB_FETCH_MODE;
2387 
2388  $false = false;
2389 
2390  if (!empty($this->metaColumnsSQL)) {
2391 
2392  $schema = false;
2393  $this->_findschema($table,$schema);
2394 
2395  $save = $ADODB_FETCH_MODE;
2396  $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
2397  if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
2398  $rs = $this->Execute(sprintf($this->metaColumnsSQL,($normalize)?strtoupper($table):$table));
2399  if (isset($savem)) $this->SetFetchMode($savem);
2400  $ADODB_FETCH_MODE = $save;
2401  if ($rs === false || $rs->EOF) return $false;
2402 
2403  $retarr = array();
2404  while (!$rs->EOF) { //print_r($rs->fields);
2405  $fld = new ADOFieldObject();
2406  $fld->name = $rs->fields[0];
2407  $fld->type = $rs->fields[1];
2408  if (isset($rs->fields[3]) && $rs->fields[3]) {
2409  if ($rs->fields[3]>0) $fld->max_length = $rs->fields[3];
2410  $fld->scale = $rs->fields[4];
2411  if ($fld->scale>0) $fld->max_length += 1;
2412  } else
2413  $fld->max_length = $rs->fields[2];
2414 
2415  if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
2416  else $retarr[strtoupper($fld->name)] = $fld;
2417  $rs->MoveNext();
2418  }
2419  $rs->Close();
2420  return $retarr;
2421  }
2422  return $false;
2423  }
2424 
2443  function MetaIndexes($table, $primary = false, $owner = false)
2444  {
2445  $false = false;
2446  return $false;
2447  }
2448 
2455  function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)
2456  {
2457  $objarr = $this->MetaColumns($table);
2458  if (!is_array($objarr)) {
2459  $false = false;
2460  return $false;
2461  }
2462  $arr = array();
2463  if ($numIndexes) {
2464  $i = 0;
2465  if ($useattnum) {
2466  foreach($objarr as $v)
2467  $arr[$v->attnum] = $v->name;
2468 
2469  } else
2470  foreach($objarr as $v) $arr[$i++] = $v->name;
2471  } else
2472  foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;
2473 
2474  return $arr;
2475  }
2476 
2487  function Concat()
2488  {
2489  $arr = func_get_args();
2490  return implode($this->concat_operator, $arr);
2491  }
2492 
2493 
2501  function DBDate($d, $isfld=false)
2502  {
2503  if (empty($d) && $d !== 0) return 'null';
2504  if ($isfld) return $d;
2505 
2506  if (is_object($d)) return $d->format($this->fmtDate);
2507 
2508 
2509  if (is_string($d) && !is_numeric($d)) {
2510  if ($d === 'null') return $d;
2511  if (strncmp($d,"'",1) === 0) {
2512  $d = _adodb_safedateq($d);
2513  return $d;
2514  }
2515  if ($this->isoDates) return "'$d'";
2516  $d = ADOConnection::UnixDate($d);
2517  }
2518 
2519  return adodb_date($this->fmtDate,$d);
2520  }
2521 
2522  function BindDate($d)
2523  {
2524  $d = $this->DBDate($d);
2525  if (strncmp($d,"'",1)) return $d;
2526 
2527  return substr($d,1,strlen($d)-2);
2528  }
2529 
2530  function BindTimeStamp($d)
2531  {
2532  $d = $this->DBTimeStamp($d);
2533  if (strncmp($d,"'",1)) return $d;
2534 
2535  return substr($d,1,strlen($d)-2);
2536  }
2537 
2538 
2546  function DBTimeStamp($ts,$isfld=false)
2547  {
2548  if (empty($ts) && $ts !== 0) return 'null';
2549  if ($isfld) return $ts;
2550  if (is_object($ts)) return $ts->format($this->fmtTimeStamp);
2551 
2552  # strlen(14) allows YYYYMMDDHHMMSS format
2553  if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14))
2554  return adodb_date($this->fmtTimeStamp,$ts);
2555 
2556  if ($ts === 'null') return $ts;
2557  if ($this->isoDates && strlen($ts) !== 14) {
2558  $ts = _adodb_safedate($ts);
2559  return "'$ts'";
2560  }
2561  $ts = ADOConnection::UnixTimeStamp($ts);
2562  return adodb_date($this->fmtTimeStamp,$ts);
2563  }
2564 
2571  static function UnixDate($v)
2572  {
2573  if (is_object($v)) {
2574  // odbtp support
2575  //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
2576  return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
2577  }
2578 
2579  if (is_numeric($v) && strlen($v) !== 8) return $v;
2580  if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|",
2581  ($v), $rr)) return false;
2582 
2583  if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0;
2584  // h-m-s-MM-DD-YY
2585  return @adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
2586  }
2587 
2588 
2595  static function UnixTimeStamp($v)
2596  {
2597  if (is_object($v)) {
2598  // odbtp support
2599  //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
2600  return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
2601  }
2602 
2603  if (!preg_match(
2604  "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|",
2605  ($v), $rr)) return false;
2606 
2607  if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;
2608 
2609  // h-m-s-MM-DD-YY
2610  if (!isset($rr[5])) return adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
2611  return @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);
2612  }
2613 
2625  function UserDate($v,$fmt='Y-m-d',$gmt=false)
2626  {
2627  $tt = $this->UnixDate($v);
2628 
2629  // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
2630  if (($tt === false || $tt == -1) && $v != false) return $v;
2631  else if ($tt == 0) return $this->emptyDate;
2632  else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
2633  }
2634 
2635  return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
2636 
2637  }
2638 
2646  function UserTimeStamp($v,$fmt='Y-m-d H:i:s',$gmt=false)
2647  {
2648  if (!isset($v)) return $this->emptyTimeStamp;
2649  # strlen(14) allows YYYYMMDDHHMMSS format
2650  if (is_numeric($v) && strlen($v)<14) return ($gmt) ? adodb_gmdate($fmt,$v) : adodb_date($fmt,$v);
2651  $tt = $this->UnixTimeStamp($v);
2652  // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
2653  if (($tt === false || $tt == -1) && $v != false) return $v;
2654  if ($tt == 0) return $this->emptyTimeStamp;
2655  return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
2656  }
2657 
2658  function escape($s,$magic_quotes=false)
2659  {
2660  return $this->addq($s,$magic_quotes);
2661  }
2662 
2666  function addq($s,$magic_quotes=false)
2667  {
2668  if (!$magic_quotes) {
2669 
2670  if ($this->replaceQuote[0] == '\\'){
2671  // only since php 4.0.5
2672  $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
2673  //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
2674  }
2675  return str_replace("'",$this->replaceQuote,$s);
2676  }
2677 
2678  // undo magic quotes for "
2679  $s = str_replace('\\"','"',$s);
2680 
2681  if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) // ' already quoted, no need to change anything
2682  return $s;
2683  else {// change \' to '' for sybase/mssql
2684  $s = str_replace('\\\\','\\',$s);
2685  return str_replace("\\'",$this->replaceQuote,$s);
2686  }
2687  }
2688 
2700  function qstr($s,$magic_quotes=false)
2701  {
2702  if (!$magic_quotes) {
2703 
2704  if ($this->replaceQuote[0] == '\\'){
2705  // only since php 4.0.5
2706  $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
2707  //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
2708  }
2709  return "'".str_replace("'",$this->replaceQuote,$s)."'";
2710  }
2711 
2712  // undo magic quotes for "
2713  $s = str_replace('\\"','"',$s);
2714 
2715  if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) // ' already quoted, no need to change anything
2716  return "'$s'";
2717  else {// change \' to '' for sybase/mssql
2718  $s = str_replace('\\\\','\\',$s);
2719  return "'".str_replace("\\'",$this->replaceQuote,$s)."'";
2720  }
2721  }
2722 
2723 
2741  function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)
2742  {
2743  global $ADODB_INCLUDED_LIB;
2744  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
2745  if ($this->pageExecuteCountRows) $rs = _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache);
2746  else $rs = _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);
2747  return $rs;
2748  }
2749 
2750 
2763  function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)
2764  {
2765  /*switch($this->dataProvider) {
2766  case 'postgres':
2767  case 'mysql':
2768  break;
2769  default: $secs2cache = 0; break;
2770  }*/
2771  $rs = $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache);
2772  return $rs;
2773  }
2774 
2775 } // end class ADOConnection
2776 
2777 
2778 
2779  //==============================================================================================
2780  // CLASS ADOFetchObj
2781  //==============================================================================================
2782 
2786  class ADOFetchObj {
2787  };
2788 
2789  //==============================================================================================
2790  // CLASS ADORecordSet_empty
2791  //==============================================================================================
2792 
2793  class ADODB_Iterator_empty implements Iterator {
2794 
2795  private $rs;
2796 
2797  function __construct($rs)
2798  {
2799  $this->rs = $rs;
2800  }
2801  function rewind()
2802  {
2803  }
2804 
2805  function valid()
2806  {
2807  return !$this->rs->EOF;
2808  }
2809 
2810  function key()
2811  {
2812  return false;
2813  }
2814 
2815  function current()
2816  {
2817  return false;
2818  }
2819 
2820  function next()
2821  {
2822  }
2823 
2824  function __call($func, $params)
2825  {
2826  return call_user_func_array(array($this->rs, $func), $params);
2827  }
2828 
2829  function hasMore()
2830  {
2831  return false;
2832  }
2833 
2834  }
2835 
2836 
2840  class ADORecordSet_empty implements IteratorAggregate
2841  {
2842  var $dataProvider = 'empty';
2843  var $databaseType = false;
2844  var $EOF = true;
2845  var $_numOfRows = 0;
2846  var $fields = false;
2847  var $connection = false;
2848  function RowCount() {return 0;}
2849  function RecordCount() {return 0;}
2850  function PO_RecordCount(){return 0;}
2851  function Close(){return true;}
2852  function FetchRow() {return false;}
2853  function FieldCount(){ return 0;}
2854  function Init() {}
2855  function getIterator() {return new ADODB_Iterator_empty($this);}
2856  function GetAssoc() {return array();}
2857  }
2858 
2859  //==============================================================================================
2860  // DATE AND TIME FUNCTIONS
2861  //==============================================================================================
2862  if (!defined('ADODB_DATE_VERSION')) include(ADODB_DIR.'/adodb-time.inc.php');
2863 
2864  //==============================================================================================
2865  // CLASS ADORecordSet
2866  //==============================================================================================
2867 
2868  class ADODB_Iterator implements Iterator {
2869 
2870  private $rs;
2871 
2872  function __construct($rs)
2873  {
2874  $this->rs = $rs;
2875  }
2876  function rewind()
2877  {
2878  $this->rs->MoveFirst();
2879  }
2880 
2881  function valid()
2882  {
2883  return !$this->rs->EOF;
2884  }
2885 
2886  function key()
2887  {
2888  return $this->rs->_currentRow;
2889  }
2890 
2891  function current()
2892  {
2893  return $this->rs->fields;
2894  }
2895 
2896  function next()
2897  {
2898  $this->rs->MoveNext();
2899  }
2900 
2901  function __call($func, $params)
2902  {
2903  return call_user_func_array(array($this->rs, $func), $params);
2904  }
2905 
2906 
2907  function hasMore()
2908  {
2909  return !$this->rs->EOF;
2910  }
2911 
2912  }
2913 
2914 
2915 
2922  class ADORecordSet implements IteratorAggregate {
2923  /*
2924  * public variables
2925  */
2926  var $dataProvider = "native";
2927  var $fields = false;
2928  var $blobSize = 100;
2929  var $canSeek = false;
2931  var $sql;
2932  var $EOF = false;
2933 
2934  var $emptyTimeStamp = '&nbsp;';
2935  var $emptyDate = '&nbsp;';
2936  var $debug = false;
2937  var $timeCreated=0;
2938 
2939  var $bind = false;
2940  var $fetchMode;
2941  var $connection = false;
2942  /*
2943  * private variables
2944  */
2945  var $_numOfRows = -1;
2946  var $_numOfFields = -1;
2947  var $_queryID = -1;
2948  var $_currentRow = -1;
2949  var $_closed = false;
2950  var $_inited = false;
2951  var $_obj;
2952  var $_names;
2954  var $_currentPage = -1;
2955  var $_atFirstPage = false;
2956  var $_atLastPage = false;
2957  var $_lastPageNo = -1;
2958  var $_maxRecordCount = 0;
2959  var $datetime = false;
2960 
2967  function ADORecordSet($queryID)
2968  {
2969  $this->_queryID = $queryID;
2970  }
2971 
2972  function getIterator()
2973  {
2974  return new ADODB_Iterator($this);
2975  }
2976 
2977  /* this is experimental - i don't really know what to return... */
2978  function __toString()
2979  {
2980  include_once(ADODB_DIR.'/toexport.inc.php');
2981  return _adodb_export($this,',',',',false,true);
2982  }
2983 
2984 
2985  function Init()
2986  {
2987  if ($this->_inited) return;
2988  $this->_inited = true;
2989  if ($this->_queryID) @$this->_initrs();
2990  else {
2991  $this->_numOfRows = 0;
2992  $this->_numOfFields = 0;
2993  }
2994  if ($this->_numOfRows != 0 && $this->_numOfFields && $this->_currentRow == -1) {
2995 
2996  $this->_currentRow = 0;
2997  if ($this->EOF = ($this->_fetch() === false)) {
2998  $this->_numOfRows = 0; // _numOfRows could be -1
2999  }
3000  } else {
3001  $this->EOF = true;
3002  }
3003  }
3004 
3005 
3026  function GetMenu($name,$defstr='',$blank1stItem=true,$multiple=false,
3027  $size=0, $selectAttr='',$compareFields0=true)
3028  {
3029  global $ADODB_INCLUDED_LIB;
3030  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
3031  return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple,
3032  $size, $selectAttr,$compareFields0);
3033  }
3034 
3035 
3036 
3044  function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='')
3045  {
3046  return $this->GetMenu($name,$defstr,$blank1stItem,$multiple,
3047  $size, $selectAttr,false);
3048  }
3049 
3050  /*
3051  Grouped Menu
3052  */
3053  function GetMenu3($name,$defstr='',$blank1stItem=true,$multiple=false,
3054  $size=0, $selectAttr='')
3055  {
3056  global $ADODB_INCLUDED_LIB;
3057  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
3058  return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple,
3059  $size, $selectAttr,false);
3060  }
3061 
3069  function GetArray($nRows = -1)
3070  {
3071  global $ADODB_EXTENSION; if ($ADODB_EXTENSION) {
3072  $results = adodb_getall($this,$nRows);
3073  return $results;
3074  }
3075  $results = array();
3076  $cnt = 0;
3077  while (!$this->EOF && $nRows != $cnt) {
3078  $results[] = $this->fields;
3079  $this->MoveNext();
3080  $cnt++;
3081  }
3082  return $results;
3083  }
3084 
3085  function GetAll($nRows = -1)
3086  {
3087  $arr = $this->GetArray($nRows);
3088  return $arr;
3089  }
3090 
3091  /*
3092  * Some databases allow multiple recordsets to be returned. This function
3093  * will return true if there is a next recordset, or false if no more.
3094  */
3095  function NextRecordSet()
3096  {
3097  return false;
3098  }
3099 
3109  function GetArrayLimit($nrows,$offset=-1)
3110  {
3111  if ($offset <= 0) {
3112  $arr = $this->GetArray($nrows);
3113  return $arr;
3114  }
3115 
3116  $this->Move($offset);
3117 
3118  $results = array();
3119  $cnt = 0;
3120  while (!$this->EOF && $nrows != $cnt) {
3121  $results[$cnt++] = $this->fields;
3122  $this->MoveNext();
3123  }
3124 
3125  return $results;
3126  }
3127 
3128 
3136  function GetRows($nRows = -1)
3137  {
3138  $arr = $this->GetArray($nRows);
3139  return $arr;
3140  }
3141 
3158  function GetAssoc($force_array = false, $first2cols = false)
3159  {
3160  global $ADODB_EXTENSION;
3161 
3162  $cols = $this->_numOfFields;
3163  if ($cols < 2) {
3164  $false = false;
3165  return $false;
3166  }
3167  $numIndex = isset($this->fields[0]) && isset($this->fields[1]);
3168  $results = array();
3169 
3170  if (!$first2cols && ($cols > 2 || $force_array)) {
3171  if ($ADODB_EXTENSION) {
3172  if ($numIndex) {
3173  while (!$this->EOF) {
3174  $results[trim($this->fields[0])] = array_slice($this->fields, 1);
3175  adodb_movenext($this);
3176  }
3177  } else {
3178  while (!$this->EOF) {
3179  // Fix for array_slice re-numbering numeric associative keys
3180  $keys = array_slice(array_keys($this->fields), 1);
3181  $sliced_array = array();
3182 
3183  foreach($keys as $key) {
3184  $sliced_array[$key] = $this->fields[$key];
3185  }
3186 
3187  $results[trim(reset($this->fields))] = $sliced_array;
3188  adodb_movenext($this);
3189  }
3190  }
3191  } else {
3192  if ($numIndex) {
3193  while (!$this->EOF) {
3194  $results[trim($this->fields[0])] = array_slice($this->fields, 1);
3195  $this->MoveNext();
3196  }
3197  } else {
3198  while (!$this->EOF) {
3199  // Fix for array_slice re-numbering numeric associative keys
3200  $keys = array_slice(array_keys($this->fields), 1);
3201  $sliced_array = array();
3202 
3203  foreach($keys as $key) {
3204  $sliced_array[$key] = $this->fields[$key];
3205  }
3206 
3207  $results[trim(reset($this->fields))] = $sliced_array;
3208  $this->MoveNext();
3209  }
3210  }
3211  }
3212  } else {
3213  if ($ADODB_EXTENSION) {
3214  // return scalar values
3215  if ($numIndex) {
3216  while (!$this->EOF) {
3217  // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
3218  $results[trim(($this->fields[0]))] = $this->fields[1];
3219  adodb_movenext($this);
3220  }
3221  } else {
3222  while (!$this->EOF) {
3223  // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
3224  $v1 = trim(reset($this->fields));
3225  $v2 = ''.next($this->fields);
3226  $results[$v1] = $v2;
3227  adodb_movenext($this);
3228  }
3229  }
3230  } else {
3231  if ($numIndex) {
3232  while (!$this->EOF) {
3233  // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
3234  $results[trim(($this->fields[0]))] = $this->fields[1];
3235  $this->MoveNext();
3236  }
3237  } else {
3238  while (!$this->EOF) {
3239  // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
3240  $v1 = trim(reset($this->fields));
3241  $v2 = ''.next($this->fields);
3242  $results[$v1] = $v2;
3243  $this->MoveNext();
3244  }
3245  }
3246  }
3247  }
3248 
3249  $ref = $results; # workaround accelerator incompat with PHP 4.4 :(
3250  return $ref;
3251  }
3252 
3253 
3261  function UserTimeStamp($v,$fmt='Y-m-d H:i:s')
3262  {
3263  if (is_numeric($v) && strlen($v)<14) return adodb_date($fmt,$v);
3264  $tt = $this->UnixTimeStamp($v);
3265  // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
3266  if (($tt === false || $tt == -1) && $v != false) return $v;
3267  if ($tt === 0) return $this->emptyTimeStamp;
3268  return adodb_date($fmt,$tt);
3269  }
3270 
3271 
3278  function UserDate($v,$fmt='Y-m-d')
3279  {
3280  $tt = $this->UnixDate($v);
3281  // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
3282  if (($tt === false || $tt == -1) && $v != false) return $v;
3283  else if ($tt == 0) return $this->emptyDate;
3284  else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
3285  }
3286  return adodb_date($fmt,$tt);
3287  }
3288 
3289 
3295  static function UnixDate($v)
3296  {
3297  return ADOConnection::UnixDate($v);
3298  }
3299 
3300 
3306  static function UnixTimeStamp($v)
3307  {
3308  return ADOConnection::UnixTimeStamp($v);
3309  }
3310 
3311 
3315  function Free()
3316  {
3317  return $this->Close();
3318  }
3319 
3320 
3324  function NumRows()
3325  {
3326  return $this->_numOfRows;
3327  }
3328 
3329 
3333  function NumCols()
3334  {
3335  return $this->_numOfFields;
3336  }
3337 
3344  function FetchRow()
3345  {
3346  if ($this->EOF) {
3347  $false = false;
3348  return $false;
3349  }
3350  $arr = $this->fields;
3351  $this->_currentRow++;
3352  if (!$this->_fetch()) $this->EOF = true;
3353  return $arr;
3354  }
3355 
3356 
3363  function FetchInto(&$arr)
3364  {
3365  if ($this->EOF) return (defined('PEAR_ERROR_RETURN')) ? new PEAR_Error('EOF',-1): false;
3366  $arr = $this->fields;
3367  $this->MoveNext();
3368  return 1; // DB_OK
3369  }
3370 
3371 
3377  function MoveFirst()
3378  {
3379  if ($this->_currentRow == 0) return true;
3380  return $this->Move(0);
3381  }
3382 
3383 
3389  function MoveLast()
3390  {
3391  if ($this->_numOfRows >= 0) return $this->Move($this->_numOfRows-1);
3392  if ($this->EOF) return false;
3393  while (!$this->EOF) {
3394  $f = $this->fields;
3395  $this->MoveNext();
3396  }
3397  $this->fields = $f;
3398  $this->EOF = false;
3399  return true;
3400  }
3401 
3402 
3408  function MoveNext()
3409  {
3410  if (!$this->EOF) {
3411  $this->_currentRow++;
3412  if ($this->_fetch()) return true;
3413  }
3414  $this->EOF = true;
3415  /* -- tested error handling when scrolling cursor -- seems useless.
3416  $conn = $this->connection;
3417  if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
3418  $fn = $conn->raiseErrorFn;
3419  $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
3420  }
3421  */
3422  return false;
3423  }
3424 
3425 
3434  function Move($rowNumber = 0)
3435  {
3436  $this->EOF = false;
3437  if ($rowNumber == $this->_currentRow) return true;
3438  if ($rowNumber >= $this->_numOfRows)
3439  if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-2;
3440 
3441  if ($this->canSeek) {
3442 
3443  if ($this->_seek($rowNumber)) {
3444  $this->_currentRow = $rowNumber;
3445  if ($this->_fetch()) {
3446  return true;
3447  }
3448  } else {
3449  $this->EOF = true;
3450  return false;
3451  }
3452  } else {
3453  if ($rowNumber < $this->_currentRow) return false;
3454  global $ADODB_EXTENSION;
3455  if ($ADODB_EXTENSION) {
3456  while (!$this->EOF && $this->_currentRow < $rowNumber) {
3457  adodb_movenext($this);
3458  }
3459  } else {
3460 
3461  while (! $this->EOF && $this->_currentRow < $rowNumber) {
3462  $this->_currentRow++;
3463 
3464  if (!$this->_fetch()) $this->EOF = true;
3465  }
3466  }
3467  return !($this->EOF);
3468  }
3469 
3470  $this->fields = false;
3471  $this->EOF = true;
3472  return false;
3473  }
3474 
3475 
3484  function Fields($colname)
3485  {
3486  return $this->fields[$colname];
3487  }
3488 
3495  function GetAssocKeys($upper=ADODB_ASSOC_CASE_UPPER)
3496  {
3497  $this->bind = array();
3498  for ($i=0; $i < $this->_numOfFields; $i++) {
3499  $o = $this->FetchField($i);
3500  switch($upper) {
3501  case ADODB_ASSOC_CASE_LOWER:
3502  $key = strtolower($o->name);
3503  break;
3504  case ADODB_ASSOC_CASE_UPPER:
3505  $key = strtoupper($o->name);
3506  break;
3507  case ADODB_ASSOC_CASE_NATIVE:
3508  default:
3509  $key = $o->name;
3510  break;
3511  }
3512  $val = $this->fetchMode == ADODB_FETCH_ASSOC ? $o->name : $i;
3513  $this->bind[$key] = $val;
3514  }
3515  }
3516 
3524  function GetRowAssoc($upper=ADODB_ASSOC_CASE_UPPER)
3525  {
3526  $record = array();
3527  if (!$this->bind) {
3528  $this->GetAssocKeys($upper);
3529  }
3530  foreach($this->bind as $k => $v) {
3531  if( array_key_exists( $v, $this->fields ) ) {
3532  $record[$k] = $this->fields[$v];
3533  } elseif( array_key_exists( $k, $this->fields ) ) {
3534  $record[$k] = $this->fields[$k];
3535  } else {
3536  # This should not happen... trigger error ?
3537  $record[$k] = null;
3538  }
3539  }
3540  return $record;
3541  }
3542 
3548  function Close()
3549  {
3550  // free connection object - this seems to globally free the object
3551  // and not merely the reference, so don't do this...
3552  // $this->connection = false;
3553  if (!$this->_closed) {
3554  $this->_closed = true;
3555  return $this->_close();
3556  } else
3557  return true;
3558  }
3559 
3565  function RecordCount() {return $this->_numOfRows;}
3566 
3567 
3568  /*
3569  * If we are using PageExecute(), this will return the maximum possible rows
3570  * that can be returned when paging a recordset.
3571  */
3572  function MaxRecordCount()
3573  {
3574  return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();
3575  }
3576 
3582  function RowCount() {return $this->_numOfRows;}
3583 
3584 
3593  function PO_RecordCount($table="", $condition="") {
3594 
3595  $lnumrows = $this->_numOfRows;
3596  // the database doesn't support native recordcount, so we do a workaround
3597  if ($lnumrows == -1 && $this->connection) {
3598  IF ($table) {
3599  if ($condition) $condition = " WHERE " . $condition;
3600  $resultrows = $this->connection->Execute("SELECT COUNT(*) FROM $table $condition");
3601  if ($resultrows) $lnumrows = reset($resultrows->fields);
3602  }
3603  }
3604  return $lnumrows;
3605  }
3606 
3607 
3611  function CurrentRow() {return $this->_currentRow;}
3612 
3618  function AbsolutePosition() {return $this->_currentRow;}
3619 
3624  function FieldCount() {return $this->_numOfFields;}
3625 
3626 
3634  function FetchField($fieldoffset = -1)
3635  {
3636  // must be defined by child class
3637 
3638  $false = false;
3639  return $false;
3640  }
3641 
3646  function FieldTypesArray()
3647  {
3648  $arr = array();
3649  for ($i=0, $max=$this->_numOfFields; $i < $max; $i++)
3650  $arr[] = $this->FetchField($i);
3651  return $arr;
3652  }
3653 
3660  function FetchObj()
3661  {
3662  $o = $this->FetchObject(false);
3663  return $o;
3664  }
3665 
3674  function FetchObject($isupper=true)
3675  {
3676  if (empty($this->_obj)) {
3677  $this->_obj = new ADOFetchObj();
3678  $this->_names = array();
3679  for ($i=0; $i <$this->_numOfFields; $i++) {
3680  $f = $this->FetchField($i);
3681  $this->_names[] = $f->name;
3682  }
3683  }
3684  $i = 0;
3685  if (PHP_VERSION >= 5) $o = clone($this->_obj);
3686  else $o = $this->_obj;
3687 
3688  for ($i=0; $i <$this->_numOfFields; $i++) {
3689  $name = $this->_names[$i];
3690  if ($isupper) $n = strtoupper($name);
3691  else $n = $name;
3692 
3693  $o->$n = $this->Fields($name);
3694  }
3695  return $o;
3696  }
3697 
3707  function FetchNextObj()
3708  {
3709  $o = $this->FetchNextObject(false);
3710  return $o;
3711  }
3712 
3713 
3725  function FetchNextObject($isupper=true)
3726  {
3727  $o = false;
3728  if ($this->_numOfRows != 0 && !$this->EOF) {
3729  $o = $this->FetchObject($isupper);
3730  $this->_currentRow++;
3731  if ($this->_fetch()) return $o;
3732  }
3733  $this->EOF = true;
3734  return $o;
3735  }
3736 
3761  function MetaType($t,$len=-1,$fieldobj=false)
3762  {
3763  if (is_object($t)) {
3764  $fieldobj = $t;
3765  $t = $fieldobj->type;
3766  $len = $fieldobj->max_length;
3767  }
3768  // changed in 2.32 to hashing instead of switch stmt for speed...
3769  static $typeMap = array(
3770  'VARCHAR' => 'C',
3771  'VARCHAR2' => 'C',
3772  'CHAR' => 'C',
3773  'C' => 'C',
3774  'STRING' => 'C',
3775  'NCHAR' => 'C',
3776  'NVARCHAR' => 'C',
3777  'VARYING' => 'C',
3778  'BPCHAR' => 'C',
3779  'CHARACTER' => 'C',
3780  'INTERVAL' => 'C', # Postgres
3781  'MACADDR' => 'C', # postgres
3782  'VAR_STRING' => 'C', # mysql
3783  ##
3784  'LONGCHAR' => 'X',
3785  'TEXT' => 'X',
3786  'NTEXT' => 'X',
3787  'M' => 'X',
3788  'X' => 'X',
3789  'CLOB' => 'X',
3790  'NCLOB' => 'X',
3791  'LVARCHAR' => 'X',
3792  ##
3793  'BLOB' => 'B',
3794  'IMAGE' => 'B',
3795  'BINARY' => 'B',
3796  'VARBINARY' => 'B',
3797  'LONGBINARY' => 'B',
3798  'B' => 'B',
3799  ##
3800  'YEAR' => 'D', // mysql
3801  'DATE' => 'D',
3802  'D' => 'D',
3803  ##
3804  'UNIQUEIDENTIFIER' => 'C', # MS SQL Server
3805  ##
3806  'SMALLDATETIME' => 'T',
3807  'TIME' => 'T',
3808  'TIMESTAMP' => 'T',
3809  'DATETIME' => 'T',
3810  'TIMESTAMPTZ' => 'T',
3811  'T' => 'T',
3812  'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
3813  ##
3814  'BOOL' => 'L',
3815  'BOOLEAN' => 'L',
3816  'BIT' => 'L',
3817  'L' => 'L',
3818  ##
3819  'COUNTER' => 'R',
3820  'R' => 'R',
3821  'SERIAL' => 'R', // ifx
3822  'INT IDENTITY' => 'R',
3823  ##
3824  'INT' => 'I',
3825  'INT2' => 'I',
3826  'INT4' => 'I',
3827  'INT8' => 'I',
3828  'INTEGER' => 'I',
3829  'INTEGER UNSIGNED' => 'I',
3830  'SHORT' => 'I',
3831  'TINYINT' => 'I',
3832  'SMALLINT' => 'I',
3833  'I' => 'I',
3834  ##
3835  'LONG' => 'N', // interbase is numeric, oci8 is blob
3836  'BIGINT' => 'N', // this is bigger than PHP 32-bit integers
3837  'DECIMAL' => 'N',
3838  'DEC' => 'N',
3839  'REAL' => 'N',
3840  'DOUBLE' => 'N',
3841  'DOUBLE PRECISION' => 'N',
3842  'SMALLFLOAT' => 'N',
3843  'FLOAT' => 'N',
3844  'NUMBER' => 'N',
3845  'NUM' => 'N',
3846  'NUMERIC' => 'N',
3847  'MONEY' => 'N',
3848 
3849  ## informix 9.2
3850  'SQLINT' => 'I',
3851  'SQLSERIAL' => 'I',
3852  'SQLSMINT' => 'I',
3853  'SQLSMFLOAT' => 'N',
3854  'SQLFLOAT' => 'N',
3855  'SQLMONEY' => 'N',
3856  'SQLDECIMAL' => 'N',
3857  'SQLDATE' => 'D',
3858  'SQLVCHAR' => 'C',
3859  'SQLCHAR' => 'C',
3860  'SQLDTIME' => 'T',
3861  'SQLINTERVAL' => 'N',
3862  'SQLBYTES' => 'B',
3863  'SQLTEXT' => 'X',
3864  ## informix 10
3865  "SQLINT8" => 'I8',
3866  "SQLSERIAL8" => 'I8',
3867  "SQLNCHAR" => 'C',
3868  "SQLNVCHAR" => 'C',
3869  "SQLLVARCHAR" => 'X',
3870  "SQLBOOL" => 'L'
3871  );
3872 
3873  $tmap = false;
3874  $t = strtoupper($t);
3875  $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N';
3876  switch ($tmap) {
3877  case 'C':
3878 
3879  // is the char field is too long, return as text field...
3880  if ($this->blobSize >= 0) {
3881  if ($len > $this->blobSize) return 'X';
3882  } else if ($len > 250) {
3883  return 'X';
3884  }
3885  return 'C';
3886 
3887  case 'I':
3888  if (!empty($fieldobj->primary_key)) return 'R';
3889  return 'I';
3890 
3891  case false:
3892  return 'N';
3893 
3894  case 'B':
3895  if (isset($fieldobj->binary))
3896  return ($fieldobj->binary) ? 'B' : 'X';
3897  return 'B';
3898 
3899  case 'D':
3900  if (!empty($this->connection) && !empty($this->connection->datetime)) return 'T';
3901  return 'D';
3902 
3903  default:
3904  if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B';
3905  return $tmap;
3906  }
3907  }
3908 
3909 
3910  function _close() {}
3911 
3915  function AbsolutePage($page=-1)
3916  {
3917  if ($page != -1) $this->_currentPage = $page;
3918  return $this->_currentPage;
3919  }
3920 
3924  function AtFirstPage($status=false)
3925  {
3926  if ($status != false) $this->_atFirstPage = $status;
3927  return $this->_atFirstPage;
3928  }
3929 
3930  function LastPageNo($page = false)
3931  {
3932  if ($page != false) $this->_lastPageNo = $page;
3933  return $this->_lastPageNo;
3934  }
3935 
3939  function AtLastPage($status=false)
3940  {
3941  if ($status != false) $this->_atLastPage = $status;
3942  return $this->_atLastPage;
3943  }
3944 
3945 } // end class ADORecordSet
3946 
3947  //==============================================================================================
3948  // CLASS ADORecordSet_array
3949  //==============================================================================================
3950 
3958  class ADORecordSet_array extends ADORecordSet
3959  {
3960  var $databaseType = 'array';
3961 
3962  var $_array; // holds the 2-dimensional data array
3963  var $_types; // the array of types of each column (C B I L M)
3964  var $_colnames; // names of each column in array
3965  var $_skiprow1; // skip 1st row because it holds column names
3966  var $_fieldobjects; // holds array of field objects
3967  var $canSeek = true;
3968  var $affectedrows = false;
3969  var $insertid = false;
3970  var $sql = '';
3971  var $compat = false;
3976  function ADORecordSet_array($fakeid=1)
3977  {
3978  global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;
3979 
3980  // fetch() on EOF does not delete $this->fields
3981  $this->compat = !empty($ADODB_COMPAT_FETCH);
3982  $this->ADORecordSet($fakeid); // fake queryID
3983  $this->fetchMode = $ADODB_FETCH_MODE;
3984  }
3985 
3986  function _transpose($addfieldnames=true)
3987  {
3988  global $ADODB_INCLUDED_LIB;
3989 
3990  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
3991  $hdr = true;
3992 
3993  $fobjs = $addfieldnames ? $this->_fieldobjects : false;
3994  adodb_transpose($this->_array, $newarr, $hdr, $fobjs);
3995  //adodb_pr($newarr);
3996 
3997  $this->_skiprow1 = false;
3998  $this->_array = $newarr;
3999  $this->_colnames = $hdr;
4000 
4001  adodb_probetypes($newarr,$this->_types);
4002 
4003  $this->_fieldobjects = array();
4004 
4005  foreach($hdr as $k => $name) {
4006  $f = new ADOFieldObject();
4007  $f->name = $name;
4008  $f->type = $this->_types[$k];
4009  $f->max_length = -1;
4010  $this->_fieldobjects[] = $f;
4011  }
4012  $this->fields = reset($this->_array);
4013 
4014  $this->_initrs();
4015 
4016  }
4017 
4029  function InitArray($array,$typearr,$colnames=false)
4030  {
4031  $this->_array = $array;
4032  $this->_types = $typearr;
4033  if ($colnames) {
4034  $this->_skiprow1 = false;
4035  $this->_colnames = $colnames;
4036  } else {
4037  $this->_skiprow1 = true;
4038  $this->_colnames = $array[0];
4039  }
4040  $this->Init();
4041  }
4050  function InitArrayFields(&$array,&$fieldarr)
4051  {
4052  $this->_array = $array;
4053  $this->_skiprow1= false;
4054  if ($fieldarr) {
4055  $this->_fieldobjects = $fieldarr;
4056  }
4057  $this->Init();
4058  }
4059 
4060  function GetArray($nRows=-1)
4061  {
4062  if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) {
4063  return $this->_array;
4064  } else {
4065  $arr = ADORecordSet::GetArray($nRows);
4066  return $arr;
4067  }
4068  }
4069 
4070  function _initrs()
4071  {
4072  $this->_numOfRows = sizeof($this->_array);
4073  if ($this->_skiprow1) $this->_numOfRows -= 1;
4074 
4075  $this->_numOfFields =(isset($this->_fieldobjects)) ?
4076  sizeof($this->_fieldobjects):sizeof($this->_types);
4077  }
4078 
4079  /* Use associative array to get fields array */
4080  function Fields($colname)
4081  {
4082  $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;
4083 
4084  if ($mode & ADODB_FETCH_ASSOC) {
4085  if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname);
4086  return $this->fields[$colname];
4087  }
4088  if (!$this->bind) {
4089  $this->bind = array();
4090  for ($i=0; $i < $this->_numOfFields; $i++) {
4091  $o = $this->FetchField($i);
4092  $this->bind[strtoupper($o->name)] = $i;
4093  }
4094  }
4095  return $this->fields[$this->bind[strtoupper($colname)]];
4096  }
4097 
4098  function FetchField($fieldOffset = -1)
4099  {
4100  if (isset($this->_fieldobjects)) {
4101  return $this->_fieldobjects[$fieldOffset];
4102  }
4103  $o = new ADOFieldObject();
4104  $o->name = $this->_colnames[$fieldOffset];
4105  $o->type = $this->_types[$fieldOffset];
4106  $o->max_length = -1; // length not known
4107 
4108  return $o;
4109  }
4110 
4111  function _seek($row)
4112  {
4113  if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) {
4114  $this->_currentRow = $row;
4115  if ($this->_skiprow1) $row += 1;
4116  $this->fields = $this->_array[$row];
4117  return true;
4118  }
4119  return false;
4120  }
4121 
4122  function MoveNext()
4123  {
4124  if (!$this->EOF) {
4125  $this->_currentRow++;
4126 
4127  $pos = $this->_currentRow;
4128 
4129  if ($this->_numOfRows <= $pos) {
4130  if (!$this->compat) $this->fields = false;
4131  } else {
4132  if ($this->_skiprow1) $pos += 1;
4133  $this->fields = $this->_array[$pos];
4134  return true;
4135  }
4136  $this->EOF = true;
4137  }
4138 
4139  return false;
4140  }
4141 
4142  function _fetch()
4143  {
4144  $pos = $this->_currentRow;
4145 
4146  if ($this->_numOfRows <= $pos) {
4147  if (!$this->compat) $this->fields = false;
4148  return false;
4149  }
4150  if ($this->_skiprow1) $pos += 1;
4151  $this->fields = $this->_array[$pos];
4152  return true;
4153  }
4154 
4155  function _close()
4156  {
4157  return true;
4158  }
4159 
4160  } // ADORecordSet_array
4161 
4162  //==============================================================================================
4163  // HELPER FUNCTIONS
4164  //==============================================================================================
4165 
4171  function ADOLoadDB($dbType)
4172  {
4173  return ADOLoadCode($dbType);
4174  }
4175 
4179  function ADOLoadCode($dbType)
4180  {
4181  global $ADODB_LASTDB;
4182 
4183  if (!$dbType) return false;
4184  $db = strtolower($dbType);
4185  switch ($db) {
4186  case 'ado':
4187  if (PHP_VERSION >= 5) $db = 'ado5';
4188  $class = 'ado';
4189  break;
4190  case 'ifx':
4191  case 'maxsql': $class = $db = 'mysqlt'; break;
4192  case 'postgres':
4193  case 'postgres8':
4194  case 'pgsql': $class = $db = 'postgres7'; break;
4195  default:
4196  $class = $db; break;
4197  }
4198 
4199  $file = ADODB_DIR."/drivers/adodb-".$db.".inc.php";
4200  @include_once($file);
4201  $ADODB_LASTDB = $class;
4202  if (class_exists("ADODB_" . $class)) return $class;
4203 
4204  //ADOConnection::outp(adodb_pr(get_declared_classes(),true));
4205  if (!file_exists($file)) ADOConnection::outp("Missing file: $file");
4206  else ADOConnection::outp("Syntax error in file: $file");
4207  return false;
4208  }
4209 
4213  function NewADOConnection($db='')
4214  {
4215  $tmp = ADONewConnection($db);
4216  return $tmp;
4217  }
4218 
4227  function ADONewConnection($db='')
4228  {
4229  GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB;
4230 
4231  if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
4232  $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;
4233  $false = false;
4234  if (($at = strpos($db,'://')) !== FALSE) {
4235  $origdsn = $db;
4236  $fakedsn = 'fake'.substr($origdsn,$at);
4237  if (($at2 = strpos($origdsn,'@/')) !== FALSE) {
4238  // special handling of oracle, which might not have host
4239  $fakedsn = str_replace('@/','@adodb-fakehost/',$fakedsn);
4240  }
4241 
4242  if ((strpos($origdsn, 'sqlite')) !== FALSE && stripos($origdsn, '%2F') === FALSE) {
4243  // special handling for SQLite, it only might have the path to the database file.
4244  // If you try to connect to a SQLite database using a dsn like 'sqlite:///path/to/database', the 'parse_url' php function
4245  // will throw you an exception with a message such as "unable to parse url"
4246  list($scheme, $path) = explode('://', $origdsn);
4247  $dsna['scheme'] = $scheme;
4248  if ($qmark = strpos($path,'?')) {
4249  $dsn['query'] = substr($path,$qmark+1);
4250  $path = substr($path,0,$qmark);
4251  }
4252  $dsna['path'] = '/' . urlencode($path);
4253  } else
4254  $dsna = @parse_url($fakedsn);
4255 
4256  if (!$dsna) {
4257  return $false;
4258  }
4259  $dsna['scheme'] = substr($origdsn,0,$at);
4260  if ($at2 !== FALSE) {
4261  $dsna['host'] = '';
4262  }
4263 
4264  if (strncmp($origdsn,'pdo',3) == 0) {
4265  $sch = explode('_',$dsna['scheme']);
4266  if (sizeof($sch)>1) {
4267 
4268  $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';
4269  if ($sch[1] == 'sqlite')
4270  $dsna['host'] = rawurlencode($sch[1].':'.rawurldecode($dsna['host']));
4271  else
4272  $dsna['host'] = rawurlencode($sch[1].':host='.rawurldecode($dsna['host']));
4273  $dsna['scheme'] = 'pdo';
4274  }
4275  }
4276 
4277  $db = @$dsna['scheme'];
4278  if (!$db) return $false;
4279  $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';
4280  $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : '';
4281  $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : '';
4282  $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial /
4283 
4284  if (isset($dsna['query'])) {
4285  $opt1 = explode('&',$dsna['query']);
4286  foreach($opt1 as $k => $v) {
4287  $arr = explode('=',$v);
4288  $opt[$arr[0]] = isset($arr[1]) ? rawurldecode($arr[1]) : 1;
4289  }
4290  } else $opt = array();
4291  }
4292  /*
4293  * phptype: Database backend used in PHP (mysql, odbc etc.)
4294  * dbsyntax: Database used with regards to SQL syntax etc.
4295  * protocol: Communication protocol to use (tcp, unix etc.)
4296  * hostspec: Host specification (hostname[:port])
4297  * database: Database to use on the DBMS server
4298  * username: User name for login
4299  * password: Password for login
4300  */
4301  if (!empty($ADODB_NEWCONNECTION)) {
4302  $obj = $ADODB_NEWCONNECTION($db);
4303 
4304  }
4305 
4306  if(empty($obj)) {
4307 
4308  if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = '';
4309  if (empty($db)) $db = $ADODB_LASTDB;
4310 
4311  if ($db != $ADODB_LASTDB) $db = ADOLoadCode($db);
4312 
4313  if (!$db) {
4314  if (isset($origdsn)) $db = $origdsn;
4315  if ($errorfn) {
4316  // raise an error
4317  $ignore = false;
4318  $errorfn('ADONewConnection', 'ADONewConnection', -998,
4319  "could not load the database driver for '$db'",
4320  $db,false,$ignore);
4321  } else
4322  ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false);
4323 
4324  return $false;
4325  }
4326 
4327  $cls = 'ADODB_'.$db;
4328  if (!class_exists($cls)) {
4329  adodb_backtrace();
4330  return $false;
4331  }
4332 
4333  $obj = new $cls();
4334  }
4335 
4336  # constructor should not fail
4337  if ($obj) {
4338  if ($errorfn) $obj->raiseErrorFn = $errorfn;
4339  if (isset($dsna)) {
4340  if (isset($dsna['port'])) $obj->port = $dsna['port'];
4341  foreach($opt as $k => $v) {
4342  switch(strtolower($k)) {
4343  case 'new':
4344  $nconnect = true; $persist = true; break;
4345  case 'persist':
4346  case 'persistent': $persist = $v; break;
4347  case 'debug': $obj->debug = (integer) $v; break;
4348  #ibase
4349  case 'role': $obj->role = $v; break;
4350  case 'dialect': $obj->dialect = (integer) $v; break;
4351  case 'charset': $obj->charset = $v; $obj->charSet=$v; break;
4352  case 'buffers': $obj->buffers = $v; break;
4353  case 'fetchmode': $obj->SetFetchMode($v); break;
4354  #ado
4355  case 'charpage': $obj->charPage = $v; break;
4356  #mysql, mysqli
4357  case 'clientflags': $obj->clientFlags = $v; break;
4358  #mysql, mysqli, postgres
4359  case 'port': $obj->port = $v; break;
4360  #mysqli
4361  case 'socket': $obj->socket = $v; break;
4362  #oci8
4363  case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break;
4364  case 'cachesecs': $obj->cacheSecs = $v; break;
4365  case 'memcache':
4366  $varr = explode(':',$v);
4367  $vlen = sizeof($varr);
4368  if ($vlen == 0) break;
4369  $obj->memCache = true;
4370  $obj->memCacheHost = explode(',',$varr[0]);
4371  if ($vlen == 1) break;
4372  $obj->memCachePort = $varr[1];
4373  if ($vlen == 2) break;
4374  $obj->memCacheCompress = $varr[2] ? true : false;
4375  break;
4376  }
4377  }
4378  if (empty($persist))
4379  $ok = $obj->Connect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
4380  else if (empty($nconnect))
4381  $ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
4382  else
4383  $ok = $obj->NConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
4384 
4385  if (!$ok) return $false;
4386  }
4387  }
4388  return $obj;
4389  }
4390 
4391 
4392 
4393  // $perf == true means called by NewPerfMonitor(), otherwise for data dictionary
4394  function _adodb_getdriver($provider,$drivername,$perf=false)
4395  {
4396  switch ($provider) {
4397  case 'odbtp': if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6);
4398  case 'odbc' : if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5);
4399  case 'ado' : if (strncmp('ado_',$drivername,4)==0) return substr($drivername,4);
4400  case 'native': break;
4401  default:
4402  return $provider;
4403  }
4404 
4405  switch($drivername) {
4406  case 'mysqlt':
4407  case 'mysqli':
4408  $drivername='mysql';
4409  break;
4410  case 'postgres7':
4411  case 'postgres8':
4412  $drivername = 'postgres';
4413  break;
4414  case 'firebird15': $drivername = 'firebird'; break;
4415  case 'oracle': $drivername = 'oci8'; break;
4416  case 'access': if ($perf) $drivername = ''; break;
4417  case 'db2' : break;
4418  case 'sapdb' : break;
4419  default:
4420  $drivername = 'generic';
4421  break;
4422  }
4423  return $drivername;
4424  }
4425 
4426  function NewPerfMonitor(&$conn)
4427  {
4428  $false = false;
4429  $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType,true);
4430  if (!$drivername || $drivername == 'generic') return $false;
4431  include_once(ADODB_DIR.'/adodb-perf.inc.php');
4432  @include_once(ADODB_DIR."/perf/perf-$drivername.inc.php");
4433  $class = "Perf_$drivername";
4434  if (!class_exists($class)) return $false;
4435  $perf = new $class($conn);
4436 
4437  return $perf;
4438  }
4439 
4440  function NewDataDictionary(&$conn,$drivername=false)
4441  {
4442  $false = false;
4443  if (!$drivername) $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType);
4444 
4445  include_once(ADODB_DIR.'/adodb-lib.inc.php');
4446  include_once(ADODB_DIR.'/adodb-datadict.inc.php');
4447  $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php";
4448 
4449  if (!file_exists($path)) {
4450  ADOConnection::outp("Dictionary driver '$path' not available");
4451  return $false;
4452  }
4453  include_once($path);
4454  $class = "ADODB2_$drivername";
4455  $dict = new $class();
4456  $dict->dataProvider = $conn->dataProvider;
4457  $dict->connection = $conn;
4458  $dict->upperName = strtoupper($drivername);
4459  $dict->quote = $conn->nameQuote;
4460  if (!empty($conn->_connectionID))
4461  $dict->serverInfo = $conn->ServerInfo();
4462 
4463  return $dict;
4464  }
4465 
4466 
4467 
4468  /*
4469  Perform a print_r, with pre tags for better formatting.
4470  */
4471  function adodb_pr($var,$as_string=false)
4472  {
4473  if ($as_string) ob_start();
4474 
4475  if (isset($_SERVER['HTTP_USER_AGENT'])) {
4476  echo " <pre>\n";print_r($var);echo "</pre>\n";
4477  } else
4478  print_r($var);
4479 
4480  if ($as_string) {
4481  $s = ob_get_contents();
4482  ob_end_clean();
4483  return $s;
4484  }
4485  }
4486 
4487  /*
4488  Perform a stack-crawl and pretty print it.
4489 
4490  @param printOrArr Pass in a boolean to indicate print, or an $exception->trace array (assumes that print is true then).
4491  @param levels Number of levels to display
4492  */
4493  function adodb_backtrace($printOrArr=true,$levels=9999,$ishtml=null)
4494  {
4495  global $ADODB_INCLUDED_LIB;
4496  if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
4497  return _adodb_backtrace($printOrArr,$levels,0,$ishtml);
4498  }
4499 
4500 
4501 }
4502 ?>




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.