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