一个连接两个不同MYSQL数据库的PHP程序
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-24
<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> |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 一个高ai的分页函数和一个url函数下一篇: 教你如何把一篇文章按要求分段
关于一个连接两个不同MYSQL数据库的PHP程序的所有评论