连接到一个项目中的不同数据库

时间:2014-12-28 22:23:42

标签: php mysql zend-framework

我的问题是连接到Zend Framework 1中的两个不同的数据库。此时我只使用一个,并以这种方式连接到此数据库:

的application.ini

resources.view[] =
resources.db.adapter = PDO_MYSQL
resources.db.params.dbname = "fish"
resources.db.params.password = "root"
resources.db.params.username = "root"
resources.db.params.host = "localhost"

bootstrap.php中

public function _initDbNames() {
    try {
        if ($this->hasPluginResource('db')) {
            $db = $this->getPluginResource('db');
            $db->getDbAdapter()->query('SET NAMES UTF8');
        }
    } catch (Exception $e) {
        echo "Blad polaczenia z baza danych: " . $e->getMessage() . PHP_EOL;
        exit(0);
    }
}

我从数据库中读取数据的方式:

 $usersTable = new Zend_Db_Table('users');
 $select = $usersTable->select()->from("users")->where("id = ?", '1');
 $this->_data = $usersTable->fetchRow($select)->toArray();

你知道如何连接到其他数据库并从她那里读取记录吗?

0 个答案:

没有答案
相关问题