fuel/fuel/core/classes/database/connection.php
public static function instance($name = null, array $config = null, $writable = true)
	{
		\Config::load('db', true);
		if ($name === null)
		{
			// Use the default instance name
			$name = \Config::get('db.active');
		}

		if ( ! $writable and ($readonly = \Config::get('db.'.$name.'.readonly', false)))
		{
			! isset(static::$_readonly[$name]) and static::$_readonly[$name] = \Arr::get($readonly, array_rand($readonly));
			$name = static::$_readonly[$name];
		}

		if ( ! isset(static::$instances[$name]))
		{
			if ($config === null)
			{
				// Load the configuration for this database
				$config = \Config::get('db.'.$name);
			}

			if ( ! isset($config['type']))
			{
				throw new \FuelException('Database type not defined in "'.$name.'" configuration or "'.$name.'" configuration does not exist');
			}

			// Set the driver class name
			$driver = '\\Database_' . ucfirst($config['type']) . '_Connection';

			// Create the database connection instance
			new $driver($name, $config);
		}

		return static::$instances[$name];
	}
public static function instance($name = null, array $config = null, $writable = true)
	{
		\Config::load('db', true);
		if ($name === null)
		{
			// Use the default instance name
			$name = \Config::get('db.active');
		}

		if ( ! $writable and ($readonly = \Config::get('db.'.$name.'.readonly', false)))
		{
			! isset(static::$_readonly[$name]) and static::$_readonly[$name] = \Arr::get($readonly, array_rand($readonly));
			$name = static::$_readonly[$name];
		}

		if ( ! isset(static::$instances[$name]))
		{
			if ($config === null)
			{
				// Load the configuration for this database
				$config = \Config::get('db.'.$name);
			}

			if ( ! isset($config['type']))
			{
				throw new \FuelException('Database type not defined in "'.$name.'" configuration or "'.$name.'" configuration does not exist');
			}

			// Set the driver class name
			$driver = '\\Database_' . ucfirst($config['type']) . '_Connection';

			// Create the database connection instance
			new $driver($name, $config);
		}

		return static::$instances[$name];
	}
public static function instance ( $ name = null , array $ config = null , $ writable = true ) { \ Config :: load ( 'db' , true ) ; if ( $ name === null ) { // Use the default instance name $ name = \ Config :: get ( 'db.active' ) ; } if ( ! $ writable and ( $ readonly = \ Config :: get ( 'db.' . $ name . '.readonly' , false ) ) ) { ! isset ( static :: $ _readonly [ $ name ] ) and static :: $ _readonly [ $ name ] = \ Arr :: get ( $ readonly , array_rand ( $ readonly ) ) ; $ name = static :: $ _readonly [ $ name ] ; } if ( ! isset ( static :: $ instances [ $ name ] ) ) { if ( $ config === null ) { // Load the configuration for this database $ config = \ Config :: get ( 'db.' . $ name ) ; } if ( ! isset ( $ config [ 'type' ] ) ) { throw new \ FuelException ( 'Database type not defined in "' . $ name . '" configuration or "' . $ name . '" configuration does not exist' ) ; } // Set the driver class name $ driver = '\\Database_' . ucfirst ( $ config [ 'type' ] ) . '_Connection' ; // Create the database connection instance new $ driver ( $ name , $ config ) ; } return static :: $ instances [ $ name ] ; }
Get a singleton Database instance. If configuration is not specified,
it will be loaded from the database configuration file using the same
group as the name.

// Load the default database
$db = static::instance();

// Create a custom configured instance
$db = static::instance('custom', $config);

@param   string $name     instance name
@param   array  $config   configuration parameters
@param   bool   $writable when replication is enabled, whether to return the master connection

@return  Database_Connection

@throws \FuelException
Get a singleton Database instance . If configuration is not specified it will be loaded from the database configuration file using the same group as the name .