一个连接两个不同MYSQL数据库的PHP程序_php基础
- WBOY原创
- 2016-05-17 09:07:11869浏览
echo "连接为 mysql
n";
$connection1 = mysql_connect('localhost', 'mysql', '') 或 die($php_errormsg);
echo "connection1 是 $connection1
n";
echo "为 mysql 用户选择测试
n";
mysql_select_db('test', $connection1) 或 @die("Error " . $php_errormsg . mysql_error());
echo“连接为 Joyce
n”;
$connection2 = mysql_connect('localhost', 'joyce', '') 或 die($php_errormsg);
echo "connection2 is $connection2
n";
echo "为 Joyce 用户选择图书
n";
$db2 = mysql_select_db('techbizbookguide', $connection2) 或 die(mysql_error());
$query1 = "从测试中选择 foo";
$query2 = "从 bookinfo 中选择标题、authorFirst、authorLast";
echo "查询测试
n";
$users = mysql_query($query1, $connection1) 或 die(mysql_error());
echo "查询图书
n";
$books = mysql_query($query2, $connection2) 或 die(mysql_error());
echo "Foos from test
n";
while (list($foo) = mysql_fetch_row($users)){
echo $foo, "
n";
}
echo "techbizbookguide 中的书籍
n";
while (list($title, $authorFirst, $authorLast) = mysql_fetch_row($books)){
//如果我们有一本“Madonna”或“Prince”的书或...
echo $title, ' by ', trim($authorFirst . ' ' . $authorLast), "
n";
}
?>
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn