/**
  * Returns the database connection used by active record.
  * By default, the "db" application component is used as the database connection.
  * You may override this method if you want to use a different database connection.
  * @return CDbConnection the database connection used by active record.
  */
 public function getDbConnection()
 {
     if (self::$db !== null) {
         return self::$db;
     } else {
         // Create CDbConnection and set properties
         self::$db = new CDbConnection();
         /*foreach(Yii::app()->db2 as $key => $value)
           self::$db->$key = $value;*/
         self::$db = Yii::app()->db2;
         // Uncomment the following lines to prove that you have two database connections
         /*
             CVarDumper::dump(Yii::app()->db);
             echo '<br />';
             CVarDumper::dump(Yii::app()->db2);
             die;
         */
         if (self::$db instanceof CDbConnection) {
             self::$db->setActive(true);
             return self::$db;
         } else {
             throw new CDbException(Yii::t('yii', 'Active Record requires a "db" CDbConnection application component.'));
         }
     }
 }
Exemple #2
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return FinaoTagnote the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }