2012-04-15 3 views
0

수 있습니까 여러 데이터베이스 주요 연결과 관련이 database.php여러 데이터베이스 연결

하지만 모델 에서의 또 다른 하나이며 나는 그것을 사이에이

같은

을 전환하려면

 $config['remote']['hostname'] = 'localhost'; 
     $config['remote']['username'] = 'root'; 
     $config['remote']['password'] = ''; 
     $config['remote']['database'] = 'countries'; 
     $config['remote']['dbdriver'] = 'mysql'; 
     $config['remote']['dbprefix'] = ''; 
     $config['remote']['pconnect'] = TRUE; 
     $config['remote']['db_debug'] = TRUE; 
     $config['remote']['cache_on'] = FALSE; 
     $config['remote']['cachedir'] = ''; 
     $config['remote']['char_set'] = 'utf8'; 
     $config['remote']['dbcollat'] = 'utf8_general_ci'; 
     $config['remote']['swap_pre'] = ''; 
     $config['remote']['autoinit'] = TRUE; 
     $config['remote']['stricton'] = FALSE; 

     $this->load->database($config); 

     $this->load->database('remote', TRUE); 
+0

이 코드는 내가 ** –

답변

1

여러 데이터베이스를 사용하기위한 기본 구문은 다음과 같습니다.

$DB1 = $this->load->database('group_one', TRUE); 
$DB2 = $this->load->database('group_two', TRUE); 

유일한 차이점 여기에 반환 된 데이터베이스 개체를 사용해야한다는 것입니다.

이 섹션을 여러 데이터베이스에

연결 참고 code igniter user guide에 메모를 참조하십시오 : "group_one"과 연결중인 특정 그룹 이름을 "group_two"로 변경 (또는 연결을 전달할 수 있습니다 값은 위에 표시된대로).

두 번째 매개 변수를 TRUE (부울 값)로 설정하면 함수가 데이터베이스 개체를 반환합니다.

+0

에 있어야합니다 모든 클래스. 컨트롤러 나 모델이 될 수 있습니다. http://codeigniter.com/user_guide/general/models.html#conn –

+0

또는 내가 모델 –

+0

연결에 매개 변수를 전달하기 위해 할 수있는 경우는 내가 위에서 설명한 방법에 작동 ** 모델에서 두 번째 데이터베이스를 config (설정)하는 습관 모델 –

관련 문제