Example #1
0
 /**
  * Creates a new DB object based on the dsn parameter OR the default
  * dsn.
  * @param \Database\DSN $dsn
  * @return \Database\DB
  * @throws \Exception
  */
 public static function newDB(\Database\DSN $dsn = null)
 {
     if (is_null($dsn)) {
         if (empty(self::$default_dsn)) {
             if (defined('PHPWS_DSN')) {
                 if (defined('PHPWS_TABLE_PREFIX')) {
                     $tbl_prefix = PHPWS_TABLE_PREFIX;
                 } else {
                     $tbl_prefix = null;
                 }
                 Database::phpwsDSNLoader(PHPWS_DSN, $tbl_prefix);
                 $dsn = self::$default_dsn;
             } else {
                 throw new \Exception(t('Default DSN not set.'));
             }
         } else {
             $dsn = self::$default_dsn;
         }
     }
     $class_name = '\\Database\\Engine\\' . $dsn->getDatabaseType() . '\\DB';
     $db = new $class_name($dsn);
     return $db;
 }
Example #2
0
 /**
  * Restores the branch connection after calling the loadHubDB
  */
 public static function restoreBranchDB()
 {
     if (isset($GLOBALS['Branch_Temp'])) {
         $prefix = $dsn = null;
         extract($GLOBALS['Branch_Temp']);
         PHPWS_DB::loadDB($dsn, $prefix);
         \Database::phpwsDSNLoader($dsn, $prefix);
     } else {
         if (defined('PHPWS_TABLE_PREFIX')) {
             $prefix = PHPWS_TABLE_PREFIX;
         } else {
             $prefix = null;
         }
         PHPWS_DB::loadDB(PHPWS_DSN, $prefix);
         \Database::phpwsDSNLoader(PHPWS_DSN, $prefix);
     }
 }