Exemplo n.º 1
0
 /**
  * Get connection to a given database using an alternative host.
  *
  * @param string $host host name for db
  * @param string $dbName Database name. See DB_ constants
  * @param string $transactions If this connection uses transactions
  * @param string $namespace Use do to specify a "namespace"/pool of related connections, e.g. "ab", "feeds", etc.<br>
  *                   This is primarily used if you want your own transactional connection to the DB not to intermingle with other transactions.
  * @return db_base
  * @see DB_
  */
 public static function GetDBConnectionUsingAltHost($host, $dbName = DB_MAIN_RW, $transactions = false, $namespace = '', $exceptions = false)
 {
     $key = "ns:{$namespace};host:{$host};db:{$dbName};t:" . ($transactions ? 1 : 0) . ";e:" . ($transactions ? 1 : 0);
     if (isset(self::$m_Connections[$key]) && is_object(self::$m_Connections[$key])) {
         return self::$m_Connections[$key];
     } else {
         global $gDBConnectInfo;
         $dbConnectionInfo = $gDBConnectInfo[$dbName];
         $db_host = $host;
         $db_port = $dbConnectionInfo['port'];
         $db_user = $dbConnectionInfo['user'];
         $db_passwd = $dbConnectionInfo['pwd'];
         $db_database = $dbConnectionInfo['db'];
         $db_timeout = $dbConnectionInfo['timeout'];
         $db_persistant = $dbConnectionInfo['persistant'];
         $dbConnection = new db_base($db_host, $db_user, $db_passwd, $db_database, $db_timeout, $db_persistant, $db_port);
         if ($transactions) {
             $dbConnection->SetAutocommit(false);
         }
         $dbConnection->m_dbResourceName = $dbName;
         $dbConnection->setThrowException($exceptions);
         self::$m_Connections[$key] = $dbConnection;
         return $dbConnection;
     }
 }