首页 > 数据库 > MySQL > 正文

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

2024-07-24 12:56:40
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。<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>  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表