[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/database/ -> databasefactory.php (source)

   1  <?php
   2  class XoopsDatabaseFactory
   3  {
   4  
   5  	function XoopsDatabaseFactory()
   6      {
   7      }
   8  
   9      /**

  10       * Get a reference to the only instance of database class and connects to DB

  11       * 

  12       * if the class has not been instantiated yet, this will also take 

  13       * care of that

  14       * 

  15       * @static

  16       * @staticvar   object  The only instance of database class

  17       * @return      object  Reference to the only instance of database class

  18       */
  19      function &getDatabaseConnection()
  20      {
  21          static $instance;
  22          if (!isset($instance)) {
  23              $file = XOOPS_ROOT_PATH.'/class/database/'.XOOPS_DB_TYPE.'database.php';
  24              require_once $file;
  25              if (!defined('XOOPS_DB_PROXY')) {
  26                  $class = 'Xoops'.ucfirst(XOOPS_DB_TYPE).'DatabaseSafe';
  27              } else {
  28                  $class = 'Xoops'.ucfirst(XOOPS_DB_TYPE).'DatabaseProxy';
  29              }
  30              $instance =& new $class();
  31              $instance->setLogger(XoopsLogger::instance());
  32              $instance->setPrefix(XOOPS_DB_PREFIX);
  33              if (!$instance->connect()) {
  34                  trigger_error("notrace:Unable to connect to database", E_USER_ERROR);
  35              }
  36          }
  37          return $instance;
  38      }
  39  
  40      /**

  41       * Gets a reference to the only instance of database class. Currently

  42       * only being used within the installer.

  43       * 

  44       * @static

  45       * @staticvar   object  The only instance of database class

  46       * @return      object  Reference to the only instance of database class

  47       */
  48      function &getDatabase()
  49      {
  50          static $database;
  51          if (!isset($database)) {
  52              $file = XOOPS_ROOT_PATH.'/class/database/'.XOOPS_DB_TYPE.'database.php';
  53              require_once $file;
  54              if (!defined('XOOPS_DB_PROXY')) {
  55                  $class = 'Xoops'.ucfirst(XOOPS_DB_TYPE).'DatabaseSafe';
  56              } else {
  57                  $class = 'Xoops'.ucfirst(XOOPS_DB_TYPE).'DatabaseProxy';
  58              }
  59              $database =& new $class();
  60          }
  61          return $database;
  62      }
  63  
  64  
  65  }
  66  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics