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

时间:2010-01-15 08:58:57   来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:ql usern"; mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error()); echo "Connection as joycen"; $connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg); echo "connection2 is $connection2n"; echo "Selecting books for joyce usern"; $db2 = mysql_select_db('techbizbookg...
  正文:

<?PHP 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"; } ?>


来源:http://www.002pc.com/master/College/Programming/PHP/11878.html

收藏到:

关于《一个连接两个不同MYSQL数据库的PHP程序》文章的评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

随机文章

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by rand() limit 10

顶出来的热门

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by diggtop desc,id desc limit 10
站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td