| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 18: |
|
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: |
|
| 26: | class XoopsDatabaseFactory
|
| 27: | {
|
| 28: | |
| 29: | |
| 30: |
|
| 31: | public function __construct()
|
| 32: | {
|
| 33: | }
|
| 34: |
|
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: |
|
| 45: | public static function getDatabaseConnection()
|
| 46: | {
|
| 47: | static $instance;
|
| 48: | if (!isset($instance)) {
|
| 49: | if (file_exists($file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php')) {
|
| 50: | require_once $file;
|
| 51: |
|
| 52: | if (!defined('XOOPS_DB_PROXY')) {
|
| 53: | $class = 'Xoops' . XOOPS_DB_TYPE . 'DatabaseSafe';
|
| 54: | } else {
|
| 55: | $class = 'Xoops' . XOOPS_DB_TYPE . 'DatabaseProxy';
|
| 56: | }
|
| 57: |
|
| 58: | $xoopsPreload = XoopsPreload::getInstance();
|
| 59: | $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class));
|
| 60: |
|
| 61: | $instance = new $class();
|
| 62: | $instance->setLogger(XoopsLogger::getInstance());
|
| 63: | $instance->setPrefix(XOOPS_DB_PREFIX);
|
| 64: | if (!$instance->connect()) {
|
| 65: | trigger_error('notrace:Unable to connect to database', E_USER_ERROR);
|
| 66: | }
|
| 67: | } else {
|
| 68: | trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
|
| 69: | }
|
| 70: | }
|
| 71: |
|
| 72: | return $instance;
|
| 73: | }
|
| 74: |
|
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: |
|
| 83: | public 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' . XOOPS_DB_TYPE . 'DatabaseSafe';
|
| 91: | } else {
|
| 92: | $class = 'Xoops' . 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: |
|
| 101: | return $database;
|
| 102: | }
|
| 103: | }
|
| 104: | |