1. 程式人生 > >如何連線兩個mysql伺服器

如何連線兩個mysql伺服器

$link1 = mysql_connect('localhost', 'root', 'root') or der('link1 connect error');
mysql_select_db('pigcms', $link1);
mysql_query("set names utf8", $link1);
$sql1 = 'select id,name,telephone from user where id=105';
$user = mysql_query($sql1, $link1) or die(mysql_error());
while ($row = mysql_fetch_assoc($user
)) { // mysql_fetch_array mysql_fetch_row print_r($row) . PHP_EOL; } $link2 = mysql_connect('113.122.1.111', 'user', 'password') or der('link2 connect error'); mysql_select_db('pigcms', $link2); mysql_query("set names utf8", $link2); $sql2 = 'select id,name,telephone from store where id=119'; $result
= mysql_query($sql2, $link2) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { print_r($row); }