how to connect multiple database if user login he take data from first db then after login he tack data from second db and configuration setting done for second db .
so i am create the component for that and trying to call on controller but i am not getting what is happend
given below is my component code pls suggest me proper way
<?php
namespace common\components;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
class AddConnection extends RActiveRecord {
public $dbadvert = null;
public function Welcome()
{
echo "Hello…Welcome to MyComponent";
if (self::$dbadvert !== null)
return self::$dbadvert;
else
{
// $User=User::model()->findByPk(Yii::app()->user->id);
// $db_name = $user->db_name;
$db_name = yiiadvanced;
self::$dbadvert = Yii::createComponent(array(
'class' => 'CDbConnection',
// other config properties...
// ‘connectionString’=>“mysql:host=localhost;dbname=”.$db_name, //dynamic database name here
'connectionString'=>"mysql:host=localhost;dbname=".$db_name, //dynamic database name here
'enableProfiling' => true,
'enableParamLogging' => true,
'username'=>'root',
'password'=> '', //password here
'charset'=>'utf8',
'emulatePrepare' => true,
'enableParamLogging'=>true,
'enableProfiling' => true,
));
Yii::app()->setComponent('dbadvert', self::$dbadvert);
if (self::$dbadvert instanceof CDbConnection)
{
Yii::app()->db->setActive(false);
Yii::app()->dbadvert->setActive(true);
return self::$dbadvert;
}
else{
throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));
}
}
}
}