Viewing Paste 439

Formated Paste

  1. // Get our proper database setup.
  2. /*
  3. $sitedb_settings['site'] = array(
  4. 'read' => array(
  5. 'server' => '127.0.0.2',
  6. 'name' => 'site',
  7. 'user' => 'site_read',
  8. 'passwd' => 'foobar',
  9. 'prefix' => '',
  10. ),
  11. 'write' => array(
  12. 'server' => '127.0.0.1',
  13. 'name' => 'site',
  14. 'user' => 'site_write',
  15. 'passwd' => 'barfoo',
  16. 'prefix' => '',
  17. ),
  18. );
  19.  
  20. Called by:
  21. Readonly: site_load_db('site');
  22. Write: site_load_db('site', true);
  23. Both: site_load_db('site', 2); or site_load_db('site', 'both');
  24.  
  25. Special connection: site_load_db('site', false, $db_connection);
  26. */
  27. function site_load_db($section, $write = false, &$connection = null)
  28. {
  29. global $sitedb_settings, $site_connections, $smcFunc, $site_section;
  30.  
  31. // No section, how lame is that.
  32. if (empty($section) && empty($site_section))
  33. trigger_error('site_query() no section set', E_ERROR);
  34. $section = empty($section) ? $site_section : $section;
  35.  
  36. // Doing both?
  37. if ($write == 'both')
  38. {
  39. site_load_db($section, 'read');
  40. $write = 'read';
  41. }
  42.  
  43. // Try to include our database information if we haven't already
  44. if (!empty($section) && !isset($site_connections[$section][$write ? 'write' : 'read']))
  45. require('/home/sites/xxxx.com/configs/settings_' . $section . '.php');
  46.  
  47. // Make the connection!
  48. $type = $write ? 'write' : 'read';
  49. if (!isset($site_connections[$section][$type]))
  50. {
  51. // No read or write data? Its old skool and needs updating.
  52. if (!sset($sitedb_settings[$section][$type]))
  53. $sitedb_settings[$section][$type] = $sitedb_settings[$section];
  54.  
  55. // The actual connection.
  56. $site_connections[$section][$type] = smf_db_initiate($sitedb_settings[$section][$type]['server'], $sitedb_settings[$section][$type]['name'], $sitedb_settings[$section][$type]['user'], $sitedb_settings[$section][$type]['passwd'], $sitedb_settings[$section][$type]['prefix']);
  57.  
  58. // Using a special connection?
  59. if ($connection != null)
  60. $connection = &$site_connections[$section][$type];
  61. }
  62. }
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin