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

时间:2010-01-04 10:40:41  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:('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 "...
  正文:

一个连接两个不同mysql数据库PHP程序代码

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

"一个连接两个不同MYSQL数据库的PHP程序代码"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Database/MySQL/2008-11-18/3791.html


关键字:

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

站内搜索: 高级搜索

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