XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
databasefactory.php
Go to the documentation of this file.
1 <?php
18 defined('XOOPS_ROOT_PATH') or die('Restricted access');
19 
28 {
32  function XoopsDatabaseFactory()
33  {
34  }
35 
46  static function &getDatabaseConnection()
47  {
48  static $instance;
49  if (!isset($instance)) {
50  if (file_exists($file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php')) {
51  require_once $file;
52 
53  if (!defined('XOOPS_DB_PROXY')) {
54  $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseSafe';
55  } else {
56  $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseProxy';
57  }
58 
60  $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class));
61 
62  $instance = new $class();
63  $instance->setLogger(XoopsLogger::getInstance());
64  $instance->setPrefix(XOOPS_DB_PREFIX);
65  if (!$instance->connect()) {
66  trigger_error('notrace:Unable to connect to database', E_USER_ERROR);
67  }
68  } else {
69  trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
70  }
71  }
72  return $instance;
73  }
74 
83  static function getDatabase()
84  {
85  static $database;
86  if (!isset($database)) {
87  if (file_exists($file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php')) {
88  include_once $file;
89  if (!defined('XOOPS_DB_PROXY')) {
90  $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseSafe';
91  } else {
92  $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseProxy';
93  }
94  unset($database);
95  $database = new $class();
96  } else {
97  trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
98  }
99  }
100  return $database;
101  }
102 }
103 
104 ?>