Пример #1
0
 /**
  * MDB2Wrapper::create() create the connection (connect and initialize)
  *
  * This function will retrieve the database-credentials from the
  * config-file. From this, it will connect tot he database and store the
  * connection so the other functions can use it.
  *
  * At the moment, this is hard-coded to mysql (see the naming
  * below), but if we should ever change to another database, this is the
  * place to add the logic).
  *
  */
 private static function create()
 {
     $uname = Config::get_config('mysql_username');
     $passwd = Config::get_config('mysql_password');
     $host = Config::get_config('mysql_host');
     $db = Config::get_config('mysql_db');
     $dsn = "mysql://{$uname}:{$passwd}@{$host}/{$db}";
     $options = array('debug' => 2, 'result_buffering' => true);
     MDB2Wrapper::$conn = MDB2::factory($dsn, $options);
     if (PEAR::isError(MDB2Wrapper::$conn)) {
         Logger::log_event(LOG_WARNING, MDB2Wrapper::$conn->getMessage());
         /* FIXME l10n, better error-reporting */
         echo "Cannot connect to database: " . MDB2Wrapper::$conn->getMessage() . "<br>\n";
         die(MDB2Wrapper::$conn->getMessage());
     }
 }