Revision #2 has been created by Steve Friedl on Dec 21, 2010, 12:58:20 AM with the memo:
Fixed broken link to other wiki article
« previous (#1) next (#3) »
Changes
Title
unchanged
Multiple-database support in Yii
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
Database
Content
changed
[...]
--------------------------
Every model defined in `protected/models/*.php` includes `GetDbConnection()` in the base class, and it returns a handle to the DB connection object for the primary database. We need to override this method in the models representing the advertising database to return the second DB connection.
Though it's possible to do this in the model definition file itself, this doesn't scale well as it would duplicate a lot of code if more than one model lives in the Advertising database. Better is to use a custom wrapper class to `CActiveRecord` where this can be centralized.
The notion of custom wrapper classes is described in <a href=[this wiki article](http://www.yiiframework.com/wiki/121/extending-common-classes-to-allow-better-customization/
">this wiki article</a>), and we'll assume that you've created a `protected/components/MyActiveRecord.php` file, and t
eachaught all of your model files to extend `MyActiveRecord` rather than `CActiveRecord`.
```php
// protected/components/MyActiveRecord.php
class MyActiveRecord extends CActiveRecord {[...]