Guest User

Untitled

a guest
Jun 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. function &getDatabase()
  2. {
  3. static $database_instances;
  4. if (!isset($database_instances )) {
  5. $database_instances = '';
  6. }
  7.  
  8. //only create a new database instance if it has not been created before
  9. if (!isset($database_instances )) {
  10. $database_instances = createDatabase();
  11. return $database_instances;
  12. } else {
  13. return $database_instances;
  14. }
  15. }
  16.  
  17. function &createDatabase()
  18. {
  19.  
  20. //get the debug configuration setting
  21. $conf =& JFactory::getConfig();
  22. $debug = $conf->getValue('config.debug');
  23.  
  24. //make sure the database model is loaded
  25. jimport('joomla.database.database');
  26. jimport('joomla.database.table' );
  27.  
  28. //get config values
  29. $conf =& JFactory::getConfig();
  30.  
  31.  
  32. //prepare the data for creating a database connection
  33. //change to however you are getting your phpBB params
  34. $host = $params->get('database_host');
  35. $user = $params->get('database_user');
  36. $password = $params->get('database_password');
  37. $database = $params->get('database_name');
  38. $prefix = $params->get('database_prefix');
  39. $driver = $params->get('database_type');
  40. $debug = $conf->getValue('config.debug');
  41.  
  42. //added extra code to prevent error when $driver is incorrect
  43. if ($driver != 'mysql' && $driver != 'mysqli') {
  44. //invalid driver
  45. JError::raiseWarning(0, JText::_('INVALID_DRIVER'));
  46. $result = false;
  47. return $result;
  48. }
  49.  
  50. //create an options variable that contains all database connection variables
  51. $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );
  52.  
  53. //create the actual connection
  54. $phpbb_database =& JDatabase::getInstance($options );
  55. if (!method_exists($jfusion_database,'Execute')){
  56. JError::raiseWarning(0, JText::_('NO_DATABASE'));
  57. $result = false;
  58. return $result;
  59. } else {
  60. //add support for UTF8
  61. $phpbb_database->Execute('SET names \'utf8\'');
  62. //support debugging
  63. $phpbb_database->debug($debug);
  64. return $phpbb_database;
  65. }
  66. }
Add Comment
Please, Sign In to add comment