Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function &getDatabase()
- {
- static $database_instances;
- if (!isset($database_instances )) {
- $database_instances = '';
- }
- //only create a new database instance if it has not been created before
- if (!isset($database_instances )) {
- $database_instances = createDatabase();
- return $database_instances;
- } else {
- return $database_instances;
- }
- }
- function &createDatabase()
- {
- //get the debug configuration setting
- $conf =& JFactory::getConfig();
- $debug = $conf->getValue('config.debug');
- //make sure the database model is loaded
- jimport('joomla.database.database');
- jimport('joomla.database.table' );
- //get config values
- $conf =& JFactory::getConfig();
- //prepare the data for creating a database connection
- //change to however you are getting your phpBB params
- $host = $params->get('database_host');
- $user = $params->get('database_user');
- $password = $params->get('database_password');
- $database = $params->get('database_name');
- $prefix = $params->get('database_prefix');
- $driver = $params->get('database_type');
- $debug = $conf->getValue('config.debug');
- //added extra code to prevent error when $driver is incorrect
- if ($driver != 'mysql' && $driver != 'mysqli') {
- //invalid driver
- JError::raiseWarning(0, JText::_('INVALID_DRIVER'));
- $result = false;
- return $result;
- }
- //create an options variable that contains all database connection variables
- $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );
- //create the actual connection
- $phpbb_database =& JDatabase::getInstance($options );
- if (!method_exists($jfusion_database,'Execute')){
- JError::raiseWarning(0, JText::_('NO_DATABASE'));
- $result = false;
- return $result;
- } else {
- //add support for UTF8
- $phpbb_database->Execute('SET names \'utf8\'');
- //support debugging
- $phpbb_database->debug($debug);
- return $phpbb_database;
- }
- }
Add Comment
Please, Sign In to add comment