Multiple Databases with Zend Framework


resources.multidb.db1.adapter        = "PDO_MYSQL"
resources.multidb.db1.isDefaultTableAdapter = true           = "localhost"
resources.multidb.db1.username       = "root"
resources.multidb.db1.password       = "password"
resources.multidb.db1.dbname         = "database1"
resources.multidb.db2.adapter        = "PDO_MYSQL"
resources.multidb.db2.isDefaultTableAdapter = false           = "localhost"
resources.multidb.db2.username       = "root"
resources.multidb.db2.password       = "password"
resources.multidb.db2.dbname         = "database2"


protected function _initDatabase ()
        $resource = $this->getPluginResource('multidb');
        Zend_Registry::set('db1', $resource->getDb('db1'));
        Zend_Registry::set('db2', $resource->getDb('db2'));

Use by calling:

$db = Zend_Registry::get('db1');
$result = $db->fetchAll ( "select * from mytable", array ());

One thought on “Multiple Databases with Zend Framework

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s