MYSQL 2個DBS連接和查詢2個DBS 2個不同的服務器MYSQL連接和查詢2不同的服務器
感謝您的幫助,
我一直在努力了一個星期得到這個上工作, ,並在本網站和其他網站上搜索了各種示例。 我想連接2分貝,在同一臺服務器上。
我可以從每個seperatly獲取數據,但我不知道如何wrire代碼合併/加入數據
這是基於很多幫助我的不正確的代碼和 如何發佈我讀過線上。歡迎任何幫助或線索。 如果我可以得到任何輸出/打印我會很樂意
// connect to db1 contact info
$host1='db1hostname';
$user1='db1user';
$password1='db1pw';
$database1='db1user';
// connect to db2, phone call info
$host2='db2hostname';
$user2='db2user';
$password2='db2pw';
$database2='db2user';
$connect1 = mysql_connect($host1, $user1, $password1) OR DIE
('Unable to connect to database! Please try again later.');
$connect2 = mysql_connect($host2, $user2, $password2) OR DIE
('Unable to connect to database! Please try again later.');
// i think this is where things start to go wrong
mysql_select_db($database1, $connect1);
mysql_select_db($database2, $connect2);
// i want to join these 2 tables from diff db by the caller info
這是一個手機號碼 //數據庫2信息來自於手機通話記錄表 並且無法更改,所以我無法連接2個tbls由表的主ID ,因爲我從來不知道ID是什麼在DB2每次調用, 我希望通過主叫手機號碼連接2個數據庫表
$data = mysql_query("SELECT `m`.`id`, `m`.`created`, `m`.`caller`, `m`.`content_text`,
`c`.`iname`, `c`.`caller`
FROM database1.contacts c, database2.messages m
WHERE `c`.`caller` = `m`.`caller` ") or die(mysql_error());
// i then want to print the results to a table
while($info = mysql_fetch_array($data))
您確實需要使用'mysql_query'嗎?它超級過時並且從PHP中刪除,因此如果這是新代碼,則根本不應該使用它。 – tadman
沒有它只是我一直在使用,有一段時間沒有建立一個網站,所以這就是我知道 –
你的代碼使它看起來,他們在不同的服務器上? db1hostname,db2hostname – AbraCadaver