您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
一个连接两个不同MYSQL数据库的PHP程序
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:36:14
<HTML><BODY BGCOLOR=FFFFFF>  
<?php  
    echo "Connecting as mysql<BR> ";  
    $connection1 = mysql_connect('localhost', 'mysql', ') or die($php_errormsg);  
    echo "connection1 is $connection1<BR> ";  
    echo "Selecting test for mysql user<BR> ";  
    mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error());  
    echo "Connection as joyce<BR> ";  
    $connection2 = mysql_connect('localhost', 'joyce', ') or die($php_errormsg);  
    echo "connection2 is $connection2<BR> ";  
    echo "Selecting books for joyce user<BR> ";  
    $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> ";  
    $users = mysql_query($query1, $connection1) or die(mysql_error());  
    echo "Querying books<BR> ";  
    $books = mysql_query($query2, $connection2) or die(mysql_error());  
    echo "Foos from test<BR> ";  
    while (list($foo) = mysql_fetch_row($users)){  
        echo $foo, "<BR> ";  
    }  
    echo "Books in techbizbookguide<BR> ";  
    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> ";  
    }  
?>  
</BODY></HTML>  


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |