首页 > 后端开发 > php教程 > 连接两个不同MYSQL数据库的PHP程序

连接两个不同MYSQL数据库的PHP程序

WBOY
发布: 2016-08-08 09:33:48
原创
904 人浏览过
  
    echo "Connecting as MySQL
\n";  
    $connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg);  
    echo "connection1 is $connection1
\n";  
    echo "Selecting test for mysql user
\n";  
    mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error());  
    echo "Connection as joyce
\n";  
    $connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg);  
    echo "connection2 is $connection2
\n";  
    echo "Selecting books for joyce user
\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
\n";  
    $users = mysql_query($query1, $connection1) or die(mysql_error());  
    echo "Querying books
\n";  
    $books = mysql_query($query2, $connection2) or die(mysql_error());  
    echo "Foos from test
\n";  
    while (list($foo) = mysql_fetch_row($users)){  
        echo $foo, "
\n";  
    }  
    echo "Books in techbizbookguide
\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), "
\n";  
    }  
?>  
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板