Last active
October 27, 2016 09:46
-
-
Save bitkorn/56c82b8f3c0fbb4eef9979a0f7b08609 to your computer and use it in GitHub Desktop.
ZF2 multiple database conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* first DBConfig | |
*/ | |
$dbParamsGlobal = array( | |
'hostname' => 'localhost', | |
'database' => 'somedbname', | |
'username' => 'root', | |
'password' => 'secretpasswd', | |
); | |
$dbParamsSecond = array( | |
'hostname' => 'localhost', | |
'database' => 'otherdbname', | |
'username' => 'root', | |
'password' => 'secretpasswd', | |
); | |
return array( | |
'service_manager' => array( | |
// 'factories' => array( | |
// 'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParamsGlobal) { | |
// return new Zend\Db\Adapter\Adapter(array( | |
// 'driver' => 'Pdo_Mysql', // Pdo_Mysql, pdo also OK | |
// 'dsn' => 'mysql:dbname=' . $dbParamsGlobal['database'] . ';host=' . $dbParamsGlobal['hostname'] . ';charset=utf8', | |
// 'database' => $dbParamsGlobal['database'], | |
// 'username' => $dbParamsGlobal['username'], | |
// 'password' => $dbParamsGlobal['password'], | |
// 'hostname' => $dbParamsGlobal['hostname'], | |
// )); | |
// }, | |
// ), | |
), | |
'service_manager' => array( | |
'abstract_factories' => array( | |
'Zend\Db\Adapter\AdapterAbstractServiceFactory', | |
), | |
), | |
'db' => array( | |
// for primary db adapter that called | |
// by $sm->get('Zend\Db\Adapter\Adapter') | |
// 'username' => $dbParamsGlobal['username'], | |
// 'password' => $dbParamsGlobal['password'], | |
// 'driver' => 'Pdo', | |
// 'dsn' => 'mysql:dbname=' . $dbParamsGlobal['database'] . ';host=' . $dbParamsGlobal['hostname'] . ';charset=utf8', | |
// 'driver_options' => array( | |
// PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' | |
// ), | |
'adapters' => array( | |
'dbGlobal' => array( | |
'username' => $dbParamsGlobal['username'], | |
'password' => $dbParamsGlobal['password'], | |
'driver' => 'Pdo_Mysql', | |
'dsn' => 'mysql:dbname=' . $dbParamsGlobal['database'] . ';host=' . $dbParamsGlobal['hostname'] . ';charset=utf8', | |
'driver_options' => array( | |
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' | |
), | |
), | |
'dbSecond' => array( | |
'username' => $dbParamsSecond['username'], | |
'password' => $dbParamsSecond['password'], | |
'driver' => 'Pdo_Mysql', | |
'dsn' => 'mysql:dbname=' . $dbParamsSecond['database'] . ';host=' . $dbParamsSecond['hostname'] . ';charset=utf8', | |
'driver_options' => array( | |
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' | |
), | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment