하나의 테이블에서 데이터를 전송하고 처리 한 다음 웹 애플리케이션에 적용하는 cronjob을 작성 중입니다. 나는 이것을 위해 2 개의 별도의 데이터베이스 연결을 가지고있다. 현재 연결 자격 증명은 다른 데이터베이스를 제외하고는 동일하지만 실제로 연결되면 완전히 분리됩니다.하나의 클래스에서 다중 mysql 연결 사용하기
문제는 연결을 만들어 $ this-> staging에 클래스에 할당하고 다른 것은 $ this-> production이라고합니다. mysql_ping을 사용하여 두 연결이 모두 작동하는지 확인합니다.
쿼리가 수행되면 연결 식별자 ($ this-> staging example)가 무시되고 마지막으로 생성 된 2 개의 연결에 대해 쿼리를 시도합니다.
나는 쿼리 내에서 연결 식별자를 사용
// Connection:
$this->staging = $this->mysql($config['staging']);
$this->production = $this->mysql($config['production']);
$sql = "SELECT * FROM TABLE";
$query = mysql_query($sql,$this->staging);
// Returns an unknown table in database defined in $this->production.
은 내가 $ this-> MySQL은() 메소드로 된 mysql_connect 반환이 아닌 반환 mysql_select_db(). mysql_select_db()를 반환하려고하면 mysql_ping이 작동하지 않습니다. 여기
는 MySQL은() 방법 : 당신은 PHP가 만든 동일한 연결을 반환 준비 (초 연결)에 연결할 때, 동일한 MySQL 서버에 연결되어 있기 때문에 문제가 발생// connect(): Connect to a database (MySQL):
private function mysql($cred) {
$connect = mysql_connect($cred['server'],$cred['username'],$cred['password']);
if($connect) {
$db = mysql_select_db($cred['database']);
if($db) {
return $connect;
} else {
$this->informer("[FATAL]","Could not make a mysql database connection on server ".$_SERVER['SERVER_ADDR']." for database: ".$cred['database']);
}
} else {
$this->informer("[FATAL]","The database credentials appears to be wrong. ".$_SERVER['SERVER_ADDR']." for the mysql database: ".$cred['database']);
}
}
mysql (..) 함수는 어떻게 생겼습니까? 올바른 연결에서 mysql_select_db를 사용합니까? – klaustopher
가능한 중복 [단일 웹 페이지에서 여러 MySQL 데이터베이스에 어떻게 연결합니까?] (http://stackoverflow.com/questions/274892/how-do-you-connect-to-multiple-mysql-databases-on- a-single-webpage) –
위의 복제물을보고 두 번째 mysql_connect 문의 네 번째 매개 변수로 'true'를 설정해야합니다. –