"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/adodb-pear.inc.php Source File", "datetime" => "Sat Dec 2 19:22:24 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

adodb-pear.inc.php

00001 <?php
00016  /*
00017  We support:
00018  
00019  DB_Common
00020  ---------
00021         query - returns PEAR_Error on error
00022         limitQuery - return PEAR_Error on error
00023         prepare - does not return PEAR_Error on error
00024         execute - does not return PEAR_Error on error
00025         setFetchMode - supports ASSOC and ORDERED
00026         errorNative
00027         quote
00028         nextID
00029         disconnect
00030         
00031         getOne
00032         getAssoc
00033         getRow
00034         getCol
00035         getAll
00036         
00037  DB_Result
00038  ---------
00039         numRows - returns -1 if not supported
00040         numCols
00041         fetchInto - does not support passing of fetchmode
00042         fetchRows - does not support passing of fetchmode
00043         free
00044  */
00045  
00046 define('ADODB_PEAR',dirname(__FILE__));
00047 include_once "PEAR.php";
00048 include_once ADODB_PEAR."/adodb-errorpear.inc.php";
00049 include_once ADODB_PEAR."/adodb.inc.php";
00050 
00051 if (!defined('DB_OK')) {
00052 define("DB_OK", 1);
00053 define("DB_ERROR",-1);
00054 
00055 // autoExecute constants
00056 define('DB_AUTOQUERY_INSERT', 1);
00057 define('DB_AUTOQUERY_UPDATE', 2);
00058 
00064 define('DB_FETCHMODE_DEFAULT', 0);
00065 
00070 define('DB_FETCHMODE_ORDERED', 1);
00071 
00076 define('DB_FETCHMODE_ASSOC', 2);
00077 
00078 /* for compatibility */
00079 
00080 define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
00081 define('DB_GETMODE_ASSOC',   DB_FETCHMODE_ASSOC);
00082 
00089 define('DB_TABLEINFO_ORDER', 1);
00090 define('DB_TABLEINFO_ORDERTABLE', 2);
00091 define('DB_TABLEINFO_FULL', 3);
00092 }
00093 
00101 class DB
00102 {
00112         function &factory($type)
00113         {
00114                 include_once(ADODB_DIR."/drivers/adodb-$type.inc.php");
00115                 $obj = &NewADOConnection($type);
00116                 if (!is_object($obj)) $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
00117                 return $obj;
00118         }
00119 
00139         function &connect($dsn, $options = false)
00140         {
00141                 if (is_array($dsn)) {
00142                         $dsninfo = $dsn;
00143                 } else {
00144                         $dsninfo = DB::parseDSN($dsn);
00145                 }
00146                 switch ($dsninfo["phptype"]) {
00147                         case 'pgsql':   $type = 'postgres7'; break;
00148                         case 'ifx':             $type = 'informix9'; break;
00149                         default:                $type = $dsninfo["phptype"]; break;
00150                 }
00151 
00152                 if (is_array($options) && isset($options["debug"]) &&
00153                         $options["debug"] >= 2) {
00154                         // expose php errors with sufficient debug level
00155                          @include_once("adodb-$type.inc.php");
00156                 } else {
00157                          @include_once("adodb-$type.inc.php");
00158                 }
00159 
00160                 @$obj =& NewADOConnection($type);
00161                 if (!is_object($obj)) {
00162                         $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
00163                         return $obj;
00164                 }
00165                 if (is_array($options)) {
00166                         foreach($options as $k => $v) {
00167                                 switch(strtolower($k)) {
00168                                 case 'persist':
00169                                 case 'persistent':      $persist = $v; break;
00170                                 #ibase
00171                                 case 'dialect':         $obj->dialect = $v; break;
00172                                 case 'charset':         $obj->charset = $v; break;
00173                                 case 'buffers':         $obj->buffers = $v; break;
00174                                 #ado
00175                                 case 'charpage':        $obj->charPage = $v; break;
00176                                 #mysql
00177                                 case 'clientflags': $obj->clientFlags = $v; break;
00178                                 }
00179                         }
00180                 } else {
00181                         $persist = false;
00182                 }
00183 
00184                 if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket'];
00185                 else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port'];
00186                 
00187                 if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
00188                 else  $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
00189                 
00190                 if (!$ok) $obj = ADODB_PEAR_Error();
00191                 return $obj;
00192         }
00193 
00199         function apiVersion()
00200         {
00201                 return 2;
00202         }
00203 
00211         function isError($value)
00212         {
00213                 if (!is_object($value)) return false;
00214                 $class = get_class($value);
00215                 return $class == 'pear_error' || is_subclass_of($value, 'pear_error') || 
00216                                 $class == 'db_error' || is_subclass_of($value, 'db_error');
00217         }
00218 
00219 
00229         function isWarning($value)
00230         {
00231                 return false;
00232                 /*
00233                 return is_object($value) &&
00234                         (get_class( $value ) == "db_warning" ||
00235                          is_subclass_of($value, "db_warning"));*/
00236         }
00237 
00270         function parseDSN($dsn)
00271         {
00272                 if (is_array($dsn)) {
00273                         return $dsn;
00274                 }
00275 
00276                 $parsed = array(
00277                         'phptype'  => false,
00278                         'dbsyntax' => false,
00279                         'protocol' => false,
00280                         'hostspec' => false,
00281                         'database' => false,
00282                         'username' => false,
00283                         'password' => false
00284                 );
00285 
00286                 // Find phptype and dbsyntax
00287                 if (($pos = strpos($dsn, '://')) !== false) {
00288                         $str = substr($dsn, 0, $pos);
00289                         $dsn = substr($dsn, $pos + 3);
00290                 } else {
00291                         $str = $dsn;
00292                         $dsn = NULL;
00293                 }
00294 
00295                 // Get phptype and dbsyntax
00296                 // $str => phptype(dbsyntax)
00297                 if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
00298                         $parsed['phptype'] = $arr[1];
00299                         $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
00300                 } else {
00301                         $parsed['phptype'] = $str;
00302                         $parsed['dbsyntax'] = $str;
00303                 }
00304 
00305                 if (empty($dsn)) {
00306                         return $parsed;
00307                 }
00308 
00309                 // Get (if found): username and password
00310                 // $dsn => username:password@protocol+hostspec/database
00311                 if (($at = strpos($dsn,'@')) !== false) {
00312                         $str = substr($dsn, 0, $at);
00313                         $dsn = substr($dsn, $at + 1);
00314                         if (($pos = strpos($str, ':')) !== false) {
00315                                 $parsed['username'] = urldecode(substr($str, 0, $pos));
00316                                 $parsed['password'] = urldecode(substr($str, $pos + 1));
00317                         } else {
00318                                 $parsed['username'] = urldecode($str);
00319                         }
00320                 }
00321 
00322                 // Find protocol and hostspec
00323                 // $dsn => protocol+hostspec/database
00324                 if (($pos=strpos($dsn, '/')) !== false) {
00325                         $str = substr($dsn, 0, $pos);
00326                         $dsn = substr($dsn, $pos + 1);
00327                 } else {
00328                         $str = $dsn;
00329                         $dsn = NULL;
00330                 }
00331 
00332                 // Get protocol + hostspec
00333                 // $str => protocol+hostspec
00334                 if (($pos=strpos($str, '+')) !== false) {
00335                         $parsed['protocol'] = substr($str, 0, $pos);
00336                         $parsed['hostspec'] = urldecode(substr($str, $pos + 1));
00337                 } else {
00338                         $parsed['hostspec'] = urldecode($str);
00339                 }
00340 
00341                 // Get dabase if any
00342                 // $dsn => database
00343                 if (!empty($dsn)) {
00344                         $parsed['database'] = $dsn;
00345                 }
00346 
00347                 return $parsed;
00348         }
00349 
00361         function assertExtension($name)
00362         {
00363                 if (!extension_loaded($name)) {
00364                         $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so';
00365                         @dl($name . $dlext);
00366                 }
00367                 if (!extension_loaded($name)) {
00368                         return false;
00369                 }
00370                 return true;
00371         }
00372 }
00373 
00374 ?>