Connect two PHP programs of different MYSQL databases

Source: Internet
Author: User
: This article mainly introduces the PHP program that connects to two different MYSQL databases. if you are interested in the PHP Tutorial, please refer to it.
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', 'job', '') 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 ";
}
?>

The above describes the PHP programs connected to two different MYSQL databases, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.