0

Here is my problem. I have a yii web project with a connection to a certain db that is defined in main.php like that:

'db'=>array(
'pdoClass' => 'NestedPDO',  
'connectionString' =>'sqlite:/var/www/my_project/protected/data/runtime/myDb.db',  
'class'            => 'CDbConnection',
'schemaCachingDuration' => 100,  
),

In one of the php scripts I run a command that copy a new database instead of the old one. The problem is that in the script I don't notice the change.
For example, If in the databsae "myDb" there is a table named Table_1 that contains 4 records and in the new "myDb" that table contains 8 records, In my php script after I will run the command that changes "myDb" I will still see that "Table_1" has 4 records.

Manquer
  • 7,390
  • 8
  • 42
  • 69
user1908466
  • 503
  • 1
  • 8
  • 17

1 Answers1

0

Yii can be configured to run multiple DB's if thats what you are looking for something like this

...
'components' => array(
   'db'=>array(
      'pdoClass' => 'NestedPDO',  
      'connectionString' =>'sqlite:/var/www/my_project/protected/data/runtime/myDb.db',  
      'class'            => 'CDbConnection',
      'schemaCachingDuration' => 100,  
     ),
   'dbNew' => array(
       'pdoClass' => 'NestedPDO',  
       'connectionString' =>'sqlite:/var/www/my_project/protected/data/runtime/myDb_new.db',  
        'schemaCachingDuration' => 100,  
        'class'            => 'CDbConnection'          // DO NOT FORGET THIS!
    ),
    ...

Once this is defined, the second database is referred to as Yii::app()->dbNew rather than Yii::app()->db, the first is also available for your regular operations of course

Manquer
  • 7,390
  • 8
  • 42
  • 69
  • If I understood you're solution right than it's not what I need. I don't need `yii`, in this case, to run another database. Just be updated that the original one was changed. The database remains in the same location, and I want to perform actions on it the same way using the same `models` that I already have. – user1908466 Feb 04 '14 at 11:50
  • You will have to manage only your query caching configurations, any application framework will expect the database to change all the time, if your query is not cached or cached incorrectly old data may be reflected, otherwise you will need no further changes. Note this is assuming the schema does not change. Yii Models(activeRecord) expects your schema to be as declared, changes to schema needs to be managed by migrations – Manquer Feb 04 '14 at 12:36