php链接另一个网站数据库,一个连接两个不同MYSQL数据库的PHP程序

echo "Connecting as mysql
\n";

$connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg);

echo "connection1 is $connection1
\n";

echo "Selecting test for mysql user
\n";

mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error());

echo "Connection as joyce
\n";

$connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg);

echo "connection2 is $connection2
\n";

echo "Selecting books for joyce user
\n";

$db2 = mysql_select_db('techbizbookguide', $connection2) or die(mysql_error());

$query1 = "select foo from test";

$query2 = "select title, authorFirst, authorLast from bookinfo";

echo "Querying test
\n";

$users = mysql_query($query1, $connection1) or die(mysql_error());

echo "Querying books
\n";

$books = mysql_query($query2, $connection2) or die(mysql_error());

echo "Foos from test
\n";

while (list($foo) = mysql_fetch_row($users)){

echo $foo, "
\n";

}

echo "Books in techbizbookguide
\n";

while (list($title, $authorFirst, $authorLast) = mysql_fetch_row($books)){

//Use trim in case we have a book by "Madonna" or "Prince" or...

echo $title, ' by ', trim($authorFirst . ' ' . $authorLast), "
\n";

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值