Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. $connection = new CDbConnection($dsn, $username, $password);
  2. $connection->active = true;
  3. Yii::app()->setComponent('clientDB', $connection);
  4.  
  5. 'db'=>array(
  6. 'connectionString' => 'mysql:host=hostIP;port=3306;dbname=database1',
  7. 'class'=>'CDbConnection',
  8. 'emulatePrepare' => true,
  9. 'username' => 'username1',
  10. 'password' => 'password1',
  11. 'charset' => 'utf8',
  12. ),
  13. 'db2'=>array(
  14. 'connectionString' => 'mysql:host=hostIP2;port=3306;dbname=database2',
  15. 'class'=>'CDbConnection',
  16. 'emulatePrepare' => true,
  17. 'username' => 'username2',
  18. 'password' => 'password2',
  19. 'charset' => 'utf8',
  20. ),
  21.  
  22. $connection->Yii::app()->db2;
  23. //then you would pass the connection into whatever you are using for your queries.
  24. //For example for an raw SQL command:
  25. $command=$connection->createCommand($sqlQuery);
  26. $command->execute();
Add Comment
Please, Sign In to add comment