2011-12-20 2 views
0

그래서 내가 알아야 할 것은 어떻게 한 번에 두 개의 데이터베이스를 연결할 수 있는가입니다. 내가하고있는 일은 하나의 db 테이블에서 정보를 가져 와서 다른 DB로 옮기는 것입니다.OOPHP는 두 개의 DB를 연결합니다

나는 다음을 시도했다. http://www.php.net/mysql_connect과 설명서에서

$db1 = mysql_connect(...); 
$db2 = mysql_connect(...); 

mysql_query('SELECT ...', $db1); 
mysql_query('INSERT ...', $db2); 

봐 :

public function sitelistingcron() 
{ 

    $sqlk = mysql_query("SELECT * FROM customer_detail WHERE approvedforsite = 2 OR approvedforsite = 3"); 


    include_once('database2.php'); 
    $fet = new Dbase(); 
     $fet->Connect(); 
     $fet->DB(); 
    while($row = mysql_fetch_array($sqlk)){ 
     //ADD 
     $this->customer_id = $row['customer_id']; 
     $this->tradingname = $row['TradingName']; 
     $this->phone  = $row['Phone']; 
     $this->street  = $row['Street']; 
     $this->city   = $row['City']; 
     $this->state  = $row['State']; 
     $this->postcode  = $row['PostCode']; 
     $this->approved = $row['approvedforsite']; 




     $this->description = $row['Description']; 

     if($this->approved = 2) 
     { 
      $sqk = mysql_query("INSERT INTO approved_business_info (id, tradingname, phonenumber, street, postcode, suburb, discription) VALUES ({$this->customer_id}, '{$this->tradingname}', '{$this->phone}', '{$this->street}', '{$this->city}', '{$this->postcode}', '{$this->description}') ON DUPLICATE KEY UPDATE id = {$this->customer_id}, tradingname ='{$this->tradingname}', phonenumber ='{$this->phone}', street = '{$this->street}', postcode = '{$this->postcode}', suburb = '{$this->city}', discription = '{$this->discription}'") or mysql_error(); 


     print "INSERT INTO approved_business_info (id, tradingname, phonenumber, street, postcode, suburb, discription) VALUES ({$this->customer_id}, '{$this->tradingname}', '{$this->phone}', '{$this->street}', '{$this->city}', '{$this->postcode}', '{$this->description}') ON DUPLICATE KEY UPDATE id = {$this->customer_id}, tradingname ='{$this->tradingname}', phonenumber ='{$this->phone}', street = '{$this->street}', postcode = '{$this->postcode}', suburb = '{$this->city}', discription = '{$this->discription}'"; 


     } 

     //REMOVE 
     if($this->approved = 3) 
     { 
      $sqk = mysql_query("DELETE FROM `approved_business_info` WHERE id = {$this->customer_id}"); 
     } 
    } 
} 
+0

'$ result = sql_query ($ conn1, $ sql1); $ sql2 = makeInsertStatements ($ result); sql_update ($ conn2, $ sql2); ' – bdares

+1

당신은 어떻게 * db *에 연결하고 있습니까? 두번 만 ...? – deceze

+1

고대의 mysql_ * 함수를 사용하지 말고 [PDO] (http://php.net/pdo) 나 [MySQLi] (http://php.net/mysqli)를 준비된 문장으로 익히십시오. –

답변

2

당신은 단순히 연결 자원을 추적하고 모든 mysql_ 함수 호출에 전달하여 mysql_ 확장을 사용하여 두 개의 별도의 DB 연결을 사용할 수 있습니다 다른 mysql_ 기능.

+0

예 당신은 그렇게 할 수 있습니다, 그러나 나는 다른 길을 찾았습니다. – RussellHarrower

+0

솔루션을 공유하는 데주의해야합니까? – deceze

관련 문제