[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/adodb_lite/ -> adodb.inc.php (source)

   1  <?php
   2  
   3  /**
   4   * ADOdb Lite is a PHP class to encapsulate multiple database APIs and is compatible with 
   5   * a subset of the ADODB Command Syntax. 
   6   * Currently supports Frontbase, MaxDB, miniSQL, MSSQL, MSSQL Pro, MySQLi, MySQLt, MySQL, PostgresSQL,
   7   * PostgresSQL64, PostgresSQL7, PostgresSQL8, SqLite, SqLite Pro, Sybase and Sybase ASE.
   8   * 
   9   */
  10  
  11  if (!defined('_ADODB_LAYER'))
  12      define('_ADODB_LAYER',1);
  13  
  14  if (!defined('ADODB_DIR'))
  15      define('ADODB_DIR', dirname(__FILE__));
  16  
  17  $ADODB_vers = 'V1.20 ADOdb Lite 2 April 2006  (c) 2005, 2006 Mark Dickenson. All rights reserved. Released LGPL.';
  18  
  19  define('ADODB_FETCH_DEFAULT',0);
  20  define('ADODB_FETCH_NUM',1);
  21  define('ADODB_FETCH_ASSOC',2);
  22  define('ADODB_FETCH_BOTH',3);
  23  
  24  GLOBAL $ADODB_FETCH_MODE;
  25  $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;    // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
  26  
  27  /**
  28   * Database connection
  29   * Usage: $db = new ADONewConnection('dbtype');
  30   * 
  31   * @access public 
  32   * @param string $dbtype 
  33   */
  34  
  35  function &ADONewConnection( $dbtype = 'mysql', $modules = '' )
  36  {
  37      global $ADODB_FETCH_MODE;
  38      $false = false;
  39  
  40      @include ( ADODB_DIR . '/adodb.config.php' );
  41  
  42      if (strpos($dbtype,'://')) {
  43          $dsn_array = @parse_url(rawurldecode($dbtype));
  44  
  45          if (!$dsn_array || !$dsn_array['scheme'])
  46              return $false;
  47  
  48          $dbtype = $dsn_array['scheme'];
  49          $modules = (!empty($dsn_array['fragment'])) ? $dsn_array['fragment'] : $modules;
  50      } else $dsn_array = array('scheme'=>'');
  51  
  52      $dbtype = strtolower($dbtype);
  53      include_once ADODB_DIR . '/adodbSQL_drivers/' . $dbtype . '/' . $dbtype . '_driver.inc';
  54      $last_module = $dbtype . '_' . 'driver';
  55      if(!empty($modules))
  56      {
  57          $module_list = explode(":", strtolower($modules));
  58          $generic_modules = array();
  59          foreach($module_list as $mod) {
  60              $mod = trim($mod);
  61              if(is_file(ADODB_DIR . '/generic_modules/' . $mod . '_module.inc'))
  62              {
  63                  $generic_modules[] = $mod;
  64              }
  65              else
  66              {
  67                  include_once ADODB_DIR . '/adodbSQL_drivers/' . $dbtype . '/' . $dbtype . '_' . $mod . '_module.inc';
  68                  $last_module = $dbtype . '_' . $mod;
  69              }
  70          }
  71  
  72          if(count($generic_modules))
  73          {
  74              foreach($generic_modules as $mod) {
  75                  include_once ADODB_DIR . '/generic_modules/' . $mod . '_module.inc';
  76                  $last_module = $mod;
  77              }
  78          }
  79      }
  80  
  81      $extention = $last_module . '_ADOConnection';
  82  
  83      $object = new $extention();
  84      $object->last_module_name = $last_module;
  85      $object->raiseErrorFn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;
  86      $object->query_count = 0;
  87      $object->query_time_total = 0;
  88  
  89      if(!empty($dsn_array['scheme']))
  90      {
  91          if (isset($dsn_array['port'])) $object->port = $dsn_array['port'];
  92          $persistent = false;
  93          $forcenew = false;
  94            if (isset($dsn_array['query'])) {
  95              $option_array = explode('&', $dsn_array['query']);
  96              foreach($option_array as $element => $value) {
  97                  $array = explode('=', $value);
  98                  $data = isset($array[1]) ? $array[1] : 1;
  99                  switch(strtolower($array[0])) {
 100                      case 'persist':
 101                      case 'persistent':
 102                          $persistent = $data;
 103                          break;
 104                      case 'debug':
 105                          $object->debug = (integer) $data;
 106                          break;
 107                      case 'fetchmode':
 108                          $ADODB_FETCH_MODE = constant($data);
 109                          break;
 110                      case 'clientflags':
 111                          $object->clientFlags = $data;
 112                          break;
 113                      case 'port':
 114                          $object->port = $data;
 115                          break;
 116                      case 'socket':
 117                          $object->socket = $data;
 118                          break;
 119                      case 'forcenew':
 120                          $forcenew = $data;
 121                          break;
 122                  }
 123              }
 124          }
 125  
 126          $dsn_array['host'] = isset($dsn_array['host']) ? $dsn_array['host'] : '';
 127          $dsn_array['user'] = isset($dsn_array['user']) ? $dsn_array['user'] : '';
 128          $dsn_array['pass'] = isset($dsn_array['pass']) ? $dsn_array['pass'] : '';
 129          $dsn_array['path'] = isset($dsn_array['path']) ? substr($dsn_array['path'], 1) : '';
 130  
 131          $result = $object->_connect($dsn_array['host'], $dsn_array['user'], $dsn_array['pass'], $dsn_array['path'], $persistent, $forcenew);
 132  
 133          if (!$result) return $false;
 134      }
 135  
 136      return $object;
 137  }
 138  
 139  /**
 140   * Alternative Database connection
 141   * Usage: $db = new NewADOConnection('dbtype');
 142   * 
 143   * @access public 
 144   * @param string $dbtype 
 145   */
 146  
 147  function &NewADOConnection($dbtype='', $module = '' )
 148  {
 149      $tmp =& ADONewConnection($dbtype, $module);
 150      return $tmp;
 151  }
 152  
 153  function &NewDataDictionary(&$connection, $dbtype=false)
 154  {
 155      if(!$dbtype)
 156          $dbtype = $connection->dbtype;
 157      include_once  ADODB_DIR . '/adodb-datadict.inc.php';
 158      include_once ADODB_DIR . '/adodbSQL_drivers/' . $dbtype . '/' . $dbtype . '_datadict.inc';
 159  
 160      $class = "ADODB2_$dbtype";
 161      $dict = new $class();
 162      $dict->connection = &$connection;
 163      $dict->upperName = strtoupper($dbtype);
 164      $dict->quote = $connection->nameQuote;
 165      $dict->debug_echo = $connection->debug_echo;
 166  
 167      return $dict;
 168  }
 169  
 170  class ADOConnection
 171  {
 172      var $connectionId = false;
 173      var $record_set = false;
 174      var $database;
 175      var $dbtype;
 176      var $host;
 177      var $open;
 178      var $password;
 179      var $username;
 180      var $persistent;
 181      var $debug = false;
 182      var $debug_echo = true;
 183      var $debug_output;
 184      var $forcenewconnection = false;
 185      var $createdatabase = false;
 186      var $last_module_name;
 187      var $socket = false;
 188      var $port = false;
 189      var $clientFlags = 0;
 190      var $nameQuote = '"';
 191      var $sysDate = false; /// name of function that returns the current date
 192      var $sysTimeStamp = false; /// name of function that returns the current timestamp
 193      var $sql;
 194      var $raiseErrorFn = false;
 195      var $query_count = 0;
 196      var $query_time_total = 0;
 197  
 198  	function ADOConnection()
 199      {
 200      }
 201  
 202      /**
 203       * Returns floating point version number of ADOdb Lite
 204       * Usage: $db->Version();
 205       * 
 206       * @access public 
 207       */
 208  
 209  	function Version()
 210      {
 211          global $ADODB_vers;
 212          return (float) substr($ADODB_vers,1);
 213      }
 214  
 215      /**
 216       * Returns true if connected to database
 217       * Usage: $db->IsConnected();
 218       * 
 219       * @access public 
 220       */
 221  
 222  	function IsConnected()
 223      {
 224          if($this->connectionId === false || $this->connectionId == false)
 225              return false;
 226          else return true;
 227      }
 228  
 229      /**
 230       * Normal Database connection
 231       * Usage: $result = $db->Connect('host', 'username', 'password', 'database');
 232       * 
 233       * @access public 
 234       * @param string $database 
 235       * @param string $host 
 236       * @param string $password 
 237       * @param string $username 
 238       * @param string $forcenew // private 
 239       */
 240  
 241  	function Connect( $host = "", $username = "", $password = "", $database = "", $forcenew = false)
 242      {
 243          return $this->_connect($host, $username, $password, $database, false, $forcenew);
 244      } 
 245  
 246      /**
 247       * Persistent Database connection
 248       * Usage: $result = $db->PConnect('host', 'username', 'password', 'database');
 249       * 
 250       * @access public 
 251       * @param string $database 
 252       * @param string $host 
 253       * @param string $password 
 254       * @param string $username 
 255       */
 256  
 257  	function PConnect( $host = "", $username = "", $password = "", $database = "")
 258      {
 259          return $this->_connect($host, $username, $password, $database, true, false);
 260      } 
 261  
 262      /**
 263       * Force New Database connection
 264       * Usage: $result = $db->NConnect('host', 'username', 'password', 'database');
 265       * 
 266       * @access public 
 267       * @param string $database 
 268       * @param string $host 
 269       * @param string $password 
 270       * @param string $username 
 271       */
 272  
 273  	function NConnect( $host = "", $username = "", $password = "", $database = "")
 274      {
 275          return $this->_connect($host, $username, $password, $database, false, true);
 276      } 
 277  
 278      /**
 279       * Returns SQL query and instantiates sql statement & resultset driver
 280       * Usage: $linkId =& $db->execute( 'SELECT * FROM foo ORDER BY id' );
 281       * 
 282       * @access public 
 283       * @param string $sql 
 284       * @return mixed Resource ID, Array
 285       */
 286  
 287      function &Execute( $sql, $inputarr = false )
 288      {
 289          $rs =& $this->do_query($sql, -1, -1, $inputarr);
 290          return $rs;
 291      } 
 292  
 293      /**
 294       * Returns SQL query and instantiates sql statement & resultset driver
 295       * Usage: $linkId =& $db->SelectLimit( 'SELECT * FROM foo ORDER BY id', $nrows, $offset );
 296       *        $nrows and $offset are optional
 297       * 
 298       * @access public 
 299       * @param string $sql 
 300       * @param string $nrows 
 301       * @param string $offset 
 302       * @return mixed Resource ID, Array
 303       */
 304  
 305      function &SelectLimit( $sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0 )
 306      {
 307          $rs =& $this->do_query( $sql, $offset, $nrows, $inputarr);
 308          return $rs;
 309      } 
 310  
 311       /**
 312       * Display debug output and database error.
 313       *
 314       * @access private 
 315       */
 316  
 317  	function outp($text, $newline = true)
 318      {
 319          global $ADODB_OUTP;
 320          $this->debug_output = "<br>\n(" . $this->dbtype . "): ".htmlspecialchars($text)."<br>\n Error (" . $this->ErrorNo() .'): '. $this->ErrorMsg() . "<br>\n";
 321  
 322          if(defined('ADODB_OUTP'))
 323          {
 324              $fn = ADODB_OUTP;
 325          } else if(isset($ADODB_OUTP))
 326          {
 327              $fn = $ADODB_OUTP;
 328          }
 329  
 330          if(defined('ADODB_OUTP') || isset($ADODB_OUTP))
 331          {
 332              $fn($this->debug_output, $newline);
 333              return;
 334          }
 335  
 336          if($this->debug_echo)
 337              echo $this->debug_output;
 338      }
 339  
 340  }
 341  
 342  /**
 343   * Empty result record set for updates, inserts, ect
 344   * 
 345   * @access private 
 346   */
 347  
 348  class ADORecordSet_empty
 349  {
 350      var $fields = false;
 351      var $EOF = true;
 352  	function MoveNext() {return;}
 353  	function RecordCount() {return 0;}
 354  	function FieldCount() {return 0;}
 355  	function EOF(){return TRUE;}
 356  	function Close(){return true;}
 357  }
 358  
 359  class ADOFieldObject { 
 360      var $name = '';
 361      var $max_length=0;
 362      var $type="";
 363  }
 364  
 365  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7