original_string: public static function instance($connectionStringOrConnectionName=null)
  	{
  		$config = Config::instance();
  
  		// Is it a connection string or name?
  		if (strpos($connectionStringOrConnectionName, '://') === false)	{
  			$connectionString = $connectionStringOrConnectionName ?
  				$config->getConnection($connectionStringOrConnectionName) :
  				$config->getDefaultConnectionString();
  		} else {
  			$connectionString = $connectionStringOrConnectionName;
  		}	
  
  		if (!$connectionString)	throw new DatabaseException("Empty connection string");
  
  		$info = static::parseConnectionUrl($connectionString);
  		$fqclass = static::loadAdapterClass($info->protocol);
  
  		try {
  			$connection = new $fqclass($info);
  			$connection->protocol = $info->protocol;
  			$connection->logging = $config->getLogging();
  			$connection->logger = $connection->logging ? $config->getLogger() : null;
  
  			if (isset($info->charset))
  				$connection->setEncoding($info->charset);
  		} catch (PDOException $e) {
  			throw new DatabaseException($e);
  		}
  		return $connection;
  	}
code: public static function instance($connectionStringOrConnectionName=null)
  	{
  		$config = Config::instance();
  
  		// Is it a connection string or name?
  		if (strpos($connectionStringOrConnectionName, '://') === false)	{
  			$connectionString = $connectionStringOrConnectionName ?
  				$config->getConnection($connectionStringOrConnectionName) :
  				$config->getDefaultConnectionString();
  		} else {
  			$connectionString = $connectionStringOrConnectionName;
  		}	
  
  		if (!$connectionString)	throw new DatabaseException("Empty connection string");
  
  		$info = static::parseConnectionUrl($connectionString);
  		$fqclass = static::loadAdapterClass($info->protocol);
  
  		try {
  			$connection = new $fqclass($info);
  			$connection->protocol = $info->protocol;
  			$connection->logging = $config->getLogging();
  			$connection->logger = $connection->logging ? $config->getLogger() : null;
  
  			if (isset($info->charset))
  				$connection->setEncoding($info->charset);
  		} catch (PDOException $e) {
  			throw new DatabaseException($e);
  		}
  		return $connection;
  	}
code_tokens: public static function instance ( $ connectionStringOrConnectionName = null ) { $ config = Config :: instance ( ) ; // Is it a connection string or name? if ( strpos ( $ connectionStringOrConnectionName , '://' ) === false ) { $ connectionString = $ connectionStringOrConnectionName ? $ config -> getConnection ( $ connectionStringOrConnectionName ) : $ config -> getDefaultConnectionString ( ) ; } else { $ connectionString = $ connectionStringOrConnectionName ; } if ( ! $ connectionString ) throw new DatabaseException ( "Empty connection string" ) ; $ info = static :: parseConnectionUrl ( $ connectionString ) ; $ fqclass = static :: loadAdapterClass ( $ info -> protocol ) ; try { $ connection = new $ fqclass ( $ info ) ; $ connection -> protocol = $ info -> protocol ; $ connection -> logging = $ config -> getLogging ( ) ; $ connection -> logger = $ connection -> logging ? $ config -> getLogger ( ) : null ; if ( isset ( $ info -> charset ) ) $ connection -> setEncoding ( $ info -> charset ) ; } catch ( PDOException $ e ) { throw new DatabaseException ( $ e ) ; } return $ connection ; }
docstring: Retrieve a database connection.
  
  @param string  A database connection string (ex. mysql://user:pass@host[:port]/dbname)
  Everything after the protocol:// part is specific to the connection adapter.
  OR
  A connection name that is set in ActiveRecord\Config
  If null it will use the default connection specified by ActiveRecord\Config->set_default_connection
  @return Connection
  @see parse_connection_url
docstring_tokens: Retrieve a database connection .