ООПХП соединяет две БД - PullRequest
0 голосов
/ 20 декабря 2011

Что мне нужно знать, так это как я могу соединить две базы данных одновременно.Я беру некоторую информацию из одной таблицы базы данных и перенесу ее в другую базу данных.

Я пробовал следующее.

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}");
        }
    }   
}

1 Ответ

2 голосов
/ 20 декабря 2011

Вы можете использовать два отдельных соединения с БД, используя расширение mysql_, просто отслеживая ресурс соединения и передавая его каждому вызову функции mysql_:

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

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

Просмотрите документацию для http://www.php.net/mysql_connect и другие mysql_ функции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...