[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/database/pdb/ -> pdb.class.php (source)

   1  <?php
   2      /**
   3       * \defgroup PDb
   4       *
   5       * Since LifeType 1.1, ADOdb is no longer part of LifeType and now all database interaction is handled via PDb,
   6       * a much tighter implementation of a database abstraction layer inspired on ADOdb (PDb is like ADOdb, with the
   7       * only difference that only those methods from ADOdb that were used by LifeType's code were implemented)
   8       *
   9       * The only noticeable difference that may make your code incompatible with this implementation is that the
  10       * function NewDataDictionary() used to get a data dictionary in ADOdb has been renamed to 
  11       * NewPDbDataDictionary() to avoid problems where both ADOdb and PDb have to coexist.
  12       */
  13      
  14      define( "PDB_DRIVER_FOLDER", PLOG_CLASS_PATH."class/database/pdb/drivers/" );
  15      
  16      /**
  17       * PDb
  18       *
  19       * LifeType's own lightweight database abstraction layer modelled after ADOdb but only implementing
  20        * those methods that are really needed.
  21       *
  22       * \ingroup PDb
  23       */
  24      class PDb 
  25      {
  26          /** 
  27           * Constructor of the class
  28           */
  29          function PDb()
  30          {            
  31          }
  32          
  33          /**
  34           * return the right driver type
  35           *
  36           * @param driver the driver name. Supported types in LifeType 1.1 are:
  37           *
  38           * - mysql
  39           *
  40           * @return An object of a class extending the PDbDriverBase class that implements the requested
  41           * database access.
  42           * @see PDbDriverBase
  43           */
  44          function getDriver( $driver )
  45          {
  46              $validDrivers = PDb::getValidDrivers();
  47  
  48              if( array_key_exists($driver, $validDrivers) ) {
  49                  // load the driver class
  50                  $driverPath = PDB_DRIVER_FOLDER.strtolower( $validDrivers[$driver] ).".class.php";
  51                  lt_include( $driverPath );
  52                  
  53                  // create an instance of it
  54                  $driverClass = new $validDrivers[$driver]();
  55                  
  56                  return( $driverClass );
  57              } else {
  58                  return false;
  59              }
  60          }
  61  
  62          /** 
  63           * Returns an array containing the names of the drivers available
  64           *
  65           * @return An associative array, where the key is the name of the driver and the
  66           * value is the name of the class implementing the driver
  67           */
  68          function getValidDrivers() 
  69          {
  70              $_drivers = Array( "mysql"    => "PDbMySQLDriver" );           
  71      
  72              return $_drivers;
  73          }
  74  
  75          /**
  76           * Returns an array with only the driver names, which are the only suitable names for the call
  77           * to PDb::getDriver
  78           *
  79           * @return An array with the driver names
  80           * @see PDb::getDriver()
  81           */
  82          function listDrivers() 
  83          {
  84              return array_keys( PDb::getValidDrivers() );
  85          }
  86      }
  87      
  88      /**
  89       * ADOdb compatibility, although this method was renamed to NewLifeTypeDataDictionary() not
  90       * to collide with ADOdb's own in those system where these two libraries may be loaded at the
  91       * same time (i.e. when the gallery2 plugin is loaded)
  92       *
  93       * @param driver A driver class whose data dictionary class we'd like to get. This method is obsolete
  94       * and you should call PDbDriverBase::getDriverDataDictionary(). This method is only here for compatibility
  95       * reasons.
  96       *
  97       * @see PDbDriverBase::getDriverDataDictionary()     
  98       * @deprecated
  99       */
 100      function NewPDbDataDictionary( $driver )
 101      {
 102          return( $driver->getDriverDataDictionary());
 103      }
 104  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics