Código PHP:
<?php
class Conexiones
{
private $connectionStrings = array();
private $connections = array();
public function __construct(array $connectionStrings)
{
$this->connectionStrings = $connectionStrings;
}
public function InitConnection($connectionName)
{
if(isset($this->connectionStrings[$connectionName]) && !isset($this->connections[$connectionName]))
{
$this->connections[$connectionName] = pg_connect($this->connectionStrings[$connectionName]) or die("Error brutal". pg_last_error());
return $this->connections[$connectionName];
}
return null;
}
public function GetConnection($connectionName)
{
if(isset($this->connections[$connectionName]))
{
return $this->connections[$connectionName];
}
return null;
}
}
$con = new Conexiones("firstConnection" => " host='localhost' port='5432' dbname='duana' user='roberto' password='*******' " ,
"secondConnection" => " host='localhost' port='5432' dbname='cosmitet' user='roberto' password='*******' ");
$con->InitConnection("firstConnection");
$con->InitConnection("secondConnection");
?>