一个连接两个不同MYSQL数据库的PHP程序
2024-07-24 12:56:40
供稿:网友
,欢迎访问网页设计爱好者web开发。<html><body bgcolor=ffffff>
<?php
echo "connecting as mysql<br>/n";
$connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg);
echo "connection1 is $connection1<br>/n";
echo "selecting test for mysql user<br>/n";
mysql_select_db('test', $connection1) or @die("error " . $php_errormsg . mysql_error());
echo "connection as joyce<br>/n";
$connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg);
echo "connection2 is $connection2<br>/n";
echo "selecting books for joyce user<br>/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<br>/n";
$users = mysql_query($query1, $connection1) or die(mysql_error());
echo "querying books<br>/n";
$books = mysql_query($query2, $connection2) or die(mysql_error());
echo "foos from test<br>/n";
while (list($foo) = mysql_fetch_row($users)){
echo $foo, "<br>/n";
}
echo "books in techbizbookguide<br>/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), "<br>/n";
}
?>
</body></html>