Php Zend Framework:一次连接多个数据库 [英] Php Zend Framework : Connecting to multiple databases one at a time

查看:32
本文介绍了Php Zend Framework:一次连接多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本,通过我的应用程序 ini.

I have written a script that goes through my application ini.

我现在遇到的问题是,当我进入下一个数据库时,它仍然从第一个数据库而不是新数据库中进行选择.

The problem I am having now is that when I get to the next database, its still selecting from the first database and not the new one.

是否可以在运行脚本时关闭连接然后打开新连接.请记住,这只是一个脚本,我没有设置引导程序.我只是设置了一个自动加载,我可以加载我的模型.

Is it possible to close a connection and then open a new connection while running a script. Remember this is just a script I have no bootstrap set. I just setup a autoload to that I can load my models.

在循环访问 ini 的各个部分时

While looping through sections of the ini

try {
        $db = Zend_Db::factory($section->database->type, $section->database->toArray());
        Zend_Db_Table::setDefaultAdapter($db);
        Zend_Registry::set('db', $db);
    } catch(Zend_Db_Adapter_Exception $e) {
        continue;   
    }

推荐答案

参见 Zend_Application_Resource_Multidb:

application.ini

[production]
resources.multidb.db1.adapter = "pdo_mysql"
resources.multidb.db1.host = "localhost"
resources.multidb.db1.username = "webuser"
resources.multidb.db1.password = "XXXX"
resources.multidb.db1.dbname = "db1"

resources.multidb.db2.adapter = "pdo_pgsql"
resources.multidb.db2.host = "example.com"
resources.multidb.db2.username = "dba"
resources.multidb.db2.password = "notthatpublic"
resources.multidb.db2.dbname = "db2"
resources.multidb.db2.default = true

index.php

$resource = $bootstrap->getPluginResource('multidb');
$db1 = $resource->getDb('db1');
$db2 = $resource->getDb('db2');
$defaultDb = $resource->getDb();

这篇关于Php Zend Framework:一次连接多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆