I am creating one database wrapper class and want to have a feature to connect with multiple database using PDO. I have connected multiple database using pdo as below.
$config = array(
'database1' => array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'users',
'port' => '',
'dbtype' => 'mysql'
),
'database2' => array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'directory',
'port' => '',
'dbtype' => 'mysql'
),
);
foreach ($config as $key => $value)
{
$this->conn[$value['database']] = new PDO("mysql:host=".$value['hostname'].";dbname=".$value['database'], $value['username'],$value['password']);
}
Is it good practice to connect multiple databases as above using any types of database (may using Oracle or Mysql or may be both same). Because my above code takes more time in loading.
I want to have a best practice as Yii or Symphony framework uses to connect db.
Can anybody have solution.
Thanks