config.php里加多配置
'db2'=>array( 'class'=>'CDbConnection', ),
AR中覆盖方法,设置其它的数据库
特别需要注意 $odb这个独立的处理,否则在连续操作的过层中,会有数据库链接变量冲突的相关问题。
public static $odb=null;
public function getDbConnection()
{
if(self::$odb!==null)
return self::$odb;
else
{
self::$odb=Yii::app()->getComponent('db2');
if(self::$odb instanceof CDbConnection)
return self::$odb;
else
throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));
}
}
转发请注明出处http://blog.martoo.cn
如有漏缺,请联系我 QQ 243008827
What’s up, yup this piece of writing is genuinely nice and I have learned lot of things from it concerning blogging. thanks.
Thanks for your marvelous posting! I quite enjoyed reading it, you’re a great author. I will remember to bookmark your blog and will often come back from now on. I want to encourage yourself to continue your great writing, have a nice day!
Thanks to my father who told me concerning this blog,
this website is in fact remarkable.
Awesome article.