Fetch all DB adapter

Hey guys,

Is there a way to grab all the DB adapters set in the config file? (CDbConnection)

For example if I have two adapters in my config file like this:


        'db1' => array(

            'class' => 'CDbConnection',

            'connectionString' => 'mysql:host=localhost;dbname=db1',

            'username' => 'db1',

            'password' => 'db1',

            'charset' => 'utf8',

        ),

        'db2' => array(

            'class' => 'CDbConnection',

            'connectionString' => 'mysql:host=localhost;dbname=db2',

            'username' => 'db2',

            'password' => 'db2',

            'charset' => 'utf8',

        ),

I would like to have an array with the name given (db1, db2). Is that even possible?

Thank you,

Maybe this method can help?

http://www.yiiframework.com/doc/api/1.1/CModule#getComponents-detail

I assume you could read through the results and check each component’s class. You’d need to treat each entry differently depending on whether it is an array or object, which is dependent on whether the component has been loaded.

Thanks a lot that helped me :)

So just for the record I did:


        $components = Yii::app()->getComponents(false);

        $dbAdapter = array();

        foreach ($components as $key => $component) {

            if (array_key_exists('class', $component) && $component['class'] == 'CDbConnection') {

                $dbAdapter[] = $key;

            }

        }

Cheers,