Yii Framework Forum: Multiple database connection problem with activerecord - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Multiple database connection problem with activerecord

#1 User is offline   manocreative 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 12-December 13

Posted 09 August 2016 - 04:37 AM

Dear Team,

I connected multiple database with dynamically but model active record not working different database.Below my code

$originalDbConnection = Yii::app()->db;
      
		    $user_hostname="localhost";
		    $latin1DbConnection = Yii::createComponent(array(      
		        'class'=>'CDbConnection',
		        'connectionString' =>'mysql:host=' . $user_hostname . ';dbname=' . $database,
		        'emulatePrepare' => Yii::app()->db->emulatePrepare,
		        'username' => $username,
		        'password' => $password,
		        'charset' => 'latin1',
		    ));

		    Yii::app()->setComponent("db",$latin1DbConnection);
		    
		    // Do the queries against the database
		   
		    $model =Example::getLableName();
		    		   	    
		    Yii::app()->setComponent("db",$originalDbConnection);

		    if($model===null)
		        throw new CHttpException(404,'The requested page does not exist.');
		    return $model;



Above the code multiple database with custom sql query working fine..but model active record not working.Please anyone can help me...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users