Show
Ignore:
Timestamp:
07/07/2008 08:25:50 PM (5 months ago)
Author:
Shadowhand
Message:

Changed the behavior of Database::instance() to allow named instances, rather than always returning the same instance.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Database.php

    r2905 r2992  
    1111 */ 
    1212class Database_Core { 
     13 
     14        // Database instances 
     15        public static $instances = array(); 
    1316 
    1417        // Global benchmark 
     
    5356         * @return  Database_Core 
    5457         */ 
    55         public static function instance($config = array()) 
    56         { 
    57                 static $instance; 
    58  
    59                 // Create the instance if it does not exist 
    60                 ($instance === NULL) and $instance = new Database($config); 
    61  
    62                 return $instance; 
     58        public static function instance($name = 'default', $config = NULL) 
     59        { 
     60                if ( ! isset(Database::$instances[$name])) 
     61                { 
     62                        // Create a new instance 
     63                        Database::$instances[$name] = new Database($config === NULL ? $name : $config); 
     64                } 
     65 
     66                return Database::$instances[$name]; 
    6367        } 
    6468