A PDO connection classto initiate multiple connection and easy access I've been looking for a way to make the database connection easy available directry from any script, and from inside other classes. And since I tend to have different connections based on what action to execute, I had to find a way to easily scale the amount of connection needed.

Here's the solution I come up with.  

I created this class:

class database{
    protected static $details = array();  //  holds all connection(s) details
    protected static $con = array();  //  holds the actual PDO connection(s)

/**
 *  addConnection()
 *  Adds a new connection
 *  @param string $alias a unique identifier for the connection
 *  @param string $db the database name
 *  @param string $un username
 *  @param string $pw password for the user
 *  @param string $desc a short description for this connection
 */
    public static function addConnection($alias,$db,$un,$pw,$desc){
        self::$details[$alias]=array('alias'=&gt;$alias,'db'=&gt;$db,'un'=&gt;$un,'pw'=&gt;$pw, 'desc'=&gt;$desc);
    }

/**
 *  getConnection()
 *  @return array of a specific connection if a valid alias is provided. Othervise return a multidimensional array of all connections.
 */
    public static function getConnections($alias=''){
        if(!empty($alias)) return self::$details[$alias];
        else return self::$details;
    }

/**
 *  setConnection()
 *  This function moves the connection to $con[] for easy access both inside and outside of this class
 *  @param string $alias a unique identifier for the connection
 *  @param string $connection the string of a new pdo connection
 */
    public static function setConnection($alias,$connection){
        self::$con[$alias] = $connection;
    }

/**
 *  useConnection()
 *  @param string $alias a unique identifier for the connection
 *  @return a specific PDO connection based on the given alias
 */
    public static function useConnection($alias){
        return self::$con[$alias];
    }
}


And this script to set/initiate multiple connections:

if(database::getConnections()){
    try{
        $dbh_options = array(
            PDO::ATTR_EMULATE_PREPARES=&gt;false,
            PDO::ATTR_DEFAULT_FETCH_MODE=&gt;PDO::FETCH_ASSOC,
            PDO::MYSQL_ATTR_INIT_COMMAND=&gt;'SET NAMES utf8',
            PDO::ATTR_ERRMODE=&gt;PDO::ERRMODE_SILENT,
        );
        foreach(database::getConnections() as $dbh){
        #   initiate connection  
            database::setConnection($dbh['alias'],new PDO('mysql:host=localhost;dbname='.$dbh['db'].';charset=utf8',$dbh['un'],$dbh['pw'],$dbh_options));
        //
        #   put the connection to a an array for easy access when coding
            $con[$dbh['alias']]=database::useConnection($dbh['alias']);
        //
        }
    } catch(PDOException $e) {
        file_put_contents('PDOException.txt',$e-&gt;getMessage(), FILE_APPEND);
        die('OBS! Something went wrong connecting to your database.&lt;br&gt;Please see PDOException.log for more details.');
    }
}


Here's how I add new connections:

database::addConnection('alias','database','username','password','a optional short description');
database::addConnection('alias2','database','username','password',null);


Amd this is how I can use the connection from whitin another class:

$select = $con['alias']-&gt;prepare('SELECT...');
$insert = $con['alias2']-&gt;prepare('INSERT INTO...');


And from other classes, I just extends the database class.

class sql extends database {
    public static function query($id){
        $query = self::$con['alias']-&gt;prepare('SELECT column FROM table WHERE id = ?');
        $query-&gt;execute(array($id));
        return $query-&gt;fetchColumn();
    }
}


But I would really like your oppinion on this. If there's any security issues with this setup?
You have some issues in code design and codestyle:


All class names must be Capitalized
Never use self::$field if $field is protected, use static::$field instead. If you use self child classes won't have access to redefine field!
Never use die() you have exceptions for this!
Save process time use if ($con = database::getConnections())
Class containing only static fields is useless and fully procedural-style, create Singleton or Registry instead.