|
本文实例讲述了Yii框架实现多数据库配置和操作的方法。分享给大家供大家参考,具体如下:
Yii的默认配置为一个数据库,不过可以很容易的支持多个数据库的操作,
这为按业务分割数据库提供了基础设施。如下所示:
//cms DB connection
'db' => (defined('DB_CONNECTION') ? array(
'connectionString' => DB_CONNECTION,
'username' => DB_USER,
'password' => DB_PWD,
'charset' => 'utf8',
'emulatePrepare' => true,
'enableParamLogging' => true,
'schemaCachingDuration' => 3600, //cache table schema
) : array()),
//member DB connection
'db_member' => (defined('DB_CONNECTION_MEMBER') ? array(
'class'=> 'CDbConnection' ,
'connectionString' => DB_CONNECTION_MEMBER,
'username' => DB_USER_MEMBER,
'password' => DB_PWD_MEMBER,
'charset' => 'utf8',
'emulatePrepare' => true,
'enableParamLogging' => true,
'schemaCachingDuration' => 3600, //cache table schema
) : array()),
|
|