여러 데이터베이스를 사용할 때 모든 활성 연결을 얻는 방법은 무엇입니까?모든 활성 DB 연결 가져 오기
foreach(Yii::app()->getComponents() as $component)
{
if ($component instanceof CDbConnection)
{
die(var_dump($component));
}
}
을하지만하지 Yii::app()->getComponents()
결과에 데이터베이스 구성 요소 모양입니다 :
이 나는 노력했다.
내 DB를 설정 :
'db'=>array(
'connectionString' => 'pgsql:host=127.0.0.1;port=yyyy;dbname=db1',
'emulatePrepare' => false,
'username' => 'user1',
'password' => 'pass1',
'schemaCachingDuration' => YII_DEBUG ? 0 : 86400000, // 1000 days
'enableParamLogging' => YII_DEBUG,
'charset' => 'utf8'
),
'db2'=>array(
'class' => 'CDbConnection',
'connectionString' => 'pgsql:host=xxx.xxx.xxx;port=xxxx;dbname=db2',
'emulatePrepare' => false,
'username' => 'user2',
'password' => 'pass2',
'schemaCachingDuration' => YII_DEBUG ? 0 : 86400000, // 1000 days
'enableParamLogging' => YII_DEBUG,
'charset' => 'utf8'
),
@Dagon 어디서 표시할까요? –
당신은'Yii :: app() -> db-> getactive()'또는'if (Yii :: app-> db-> active)' – ineersa
으로 확인할 수 있습니다. 그러나 이것은 이상한 getComponents()가 작동해야합니다. – ineersa