我使用经典连接,它通过从 application.ini 文件中读取参数在引导程序中创建。我想使用更多的外部数据库,但我无法从 application.ini 中读取它们。我更喜欢从主数据库读取参数(它是哪个外部数据库,取决于网站)。那么如何有效地在模型中建立连接?现在,我每次需要使用它时都会设置该连接。当我需要使用主数据库时,需要再次建立连接。这是非常无效的解决方案。
function joinClientDB($id)
{
$web = $this->getById($id);
$dbSettings = array();
$dbSettings['host'] = $web['web_dbHost'];
$dbSettings['username'] = $web['web_dbUsername'];
$dbSettings['password'] = $web['web_dbPassword'];
$dbSettings['dbname'] = $web['web_dbName'];
$this->_db = Zend_Db::factory('pdo_mysql', $dbSettings);
$this->_db->query('SET CHARACTER SET ' . $web['web_dbCharset']);
}
function joinDefaultDb()
{
$this->_db = Zend_Registry::get('db');
}
有没有人为我提供简单的解决方案?