Multiple Db Problem (Database Of Different Hosts)

Hello,

Im having a problem on getting a set of data from a remote database an then saving that data on my local database.

I followed the configuration for multiple database here–>http://www.yiiframework.com/wiki/123/multiple-database-support-in-yii/

On my config/main.php file, i have this configuration for multiple database:

‘db’=>array(

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


'emulatePrepare' => true,


'username' => 'root',


'password' => '12345',


'charset' => 'utf8',


  ),

‘db2’ => array(

     'connectionString' => 'mysql:host=db2.amazonaws.com;dbname=db2',


'emulatePrepare' => true,


'username' => 'webuser',


'password' => '12345',


'charset' => 'utf8',


  ),

And created an ActiveRecord file on my components folder that would handle the db2.

But when i tried getting data from db2, i got this error : Object configuration must be an array containing a "class" element.

I hope that you could help me guys…thanks :)

Try







'db2' => array(


  'class'=>'CDbConnection', //<-- add class 




  'connectionString' => 'mysql:host=db2.amazonaws.com;dbname=db2',

  'emulatePrepare' => true,

  'username' => 'webuser',

  'password' => '12345',

  'charset' => 'utf8',

),




Hi Joblo,

After putting the classon my 2nd database configuration, i got this error

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘db2.amazonaws.com’ (4)

but the username and password that i used were correct in order to access the database

do you have any ideas for it? thanks :)

That can point to several things; I would debug that step by step and check the configuration of your DB instance at Amazon. Are you sure that db2.amazonaws.com is the endpoint of your database? That sounds like having telephone number +1(23)456 :).

I just used a sample address but im using the real one on testing :)