会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
技术文档 > Web开发 > PHP
一个连接两个不同MYSQL数据库的PHP程序
发表日期:2004-07-22 18:49:19作者: 出处:  

<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>  

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00407