一個串連兩個不同MYSQL資料庫的PHP程式

來源:互聯網
上載者:User
關鍵字 一個串連兩個不同MYSQL資料庫的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"; 
  } 
?> 
 
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.