0

I am using Zend 1.11 with Doctrine 1.1.4. My application uses multiple databases.

In my bootstrap.php file, I've set up the details for two databases;

   $dbs = array(
        'global_users'=>array(
            'adapter' => 'mysqli',
            'params' => array(
                'host'     => 'localhost',
                'username' => 'root',
                'password' => '',
                'dbname'   => 'global_users',
                'charset'   => 'UTF8',
            ),
        ),
        'search_landscape'=>array(
            'adapter' => 'mysqli',
            'params' => array(
                'host'     => 'localhost',
                'username' => 'root',
                'password' => '',
                'dbname'   => 'search_landscape',
                'charset'   => 'UTF8',
            ),
        ),
    );

I've generated the Doctrine Model classes for the second database, search_landscape. I have not used the global_users database yet in the application whilst I have performed several Doctrine queries on the second database, search_landscape which is working as expected so far.

When performing the Doctrine queries, I am not defining an explicit connection to the database i.e it using the default connection, how does Doctrine know which database to connect to?

When I start to use the other databases in the application I understand I'll have to define the Doctrine connection for each of them explicitly, however right now I have not defined any explicit connections yet Doctrine seems to know which db to connect to out of the two.

Appreciate the help.

4

1 回答 1

0
Doctrine_Manager::getInstance()->getCurrentConnection();

Doctrine_Manager is a singleton object, you can set other connections as default using their names. See the Doctrine_Manager API documentation for more info.

于 2011-05-19T14:45:57.237 回答