Source for file db.php

Documentation is available at db.php

  1. <?php
  2. /**
  3. * Database connection script
  4. *
  5. * Parses the {@link db.ini } file and connects to the database.
  6. * If the db login doesn't work then die() as there is no point in continuing
  7. * without a database connection.
  8. *
  9. * @author    Stuart Prescott
  10. * @copyright  Copyright Stuart Prescott
  11. * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12. * @version    $Id$
  13. * @package    Bumblebee
  14. * @subpackage Misc
  15. */
  16.  
  17. /** Load ancillary functions */
  18. require_once 'inc/typeinfo.php';
  19.  
  20. require_once 'inc/bb/configreader.php';
  21. require_once 'inc/menu.php';
  22.  
  23. $conf = & ConfigReader::getInstance();
  24. $conf->MergeFile('db.ini');
  25.  
  26.  
  27. /**
  28. * $TABLEPREFIX is added to the beginning of all SQL table names to allow database sharing
  29. * @global string $TABLEPREFIX 
  30. */
  31. $TABLEPREFIX = $conf->value('database', 'tableprefix');
  32.  
  33. /**
  34. * import SQL functions for database lookups
  35. */
  36. require_once 'inc/formslib/sql.php';
  37.  
  38. $DB_CONNECT_DEBUG = isset($DB_CONNECT_DEBUG) ? $DB_CONNECT_DEBUG : false;
  39. $NON_FATAL_DB     = isset($NON_FATAL_DB)     ? $NON_FATAL_DB     : false;
  40.  
  41. if (($connection = mysql_pconnect($conf->value('database', 'host'),
  42.                              $conf->value('database', 'username'),
  43.                              $conf->value('database', 'passwd')) )
  44.     && ($db = mysql_select_db($conf->value('database', 'database'), $connection)) ) {
  45.   // we successfully logged on to the database
  46.   // automatically use UTF-8 for the connection encoding
  47.     db_quiet("SET NAMES 'utf8'");
  48.   $conf->status->database = true;
  49. } else {
  50.  
  51.   $errmsg  = sprintf(T_('<p>Sorry, I couldn\'t connect to the database, so there\'s nothing I can presently do. This could be due to a booking system misconfiguration, or a failure of the database subsystem.</p><p>If this persists, please contact the <a href="mailto:%s">booking system administrator</a>.</p>'), $conf->AdminEmail);
  52.  
  53.   if ($DB_CONNECT_DEBUG) {
  54.     $errmsg .= mysql_error()
  55.               .'<br />Connected using parameters <pre>'
  56.               .print_r($conf->getSection('database'),true).'</pre>';
  57.   }
  58.   $conf->status->database = false;
  59.   $conf->status->offline = true;
  60.  
  61.   $conf->status->messages[] = $errmsg;
  62.  
  63.   if ($NON_FATAL_DB) {
  64.     trigger_error($errmsg, E_USER_NOTICE);
  65.   }
  66. }
  67.  
  68.  
  69. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:16 +0000 by phpDocumentor 1.3.0