One PHP program connecting two different MYSQL databases
Source: Internet
Author: User
HTMLBODYBGCOLORFFFFFF? PhpechoConnectingasmysqlBRn; $ connection1mysql_connect (localhost, mysql,) ordie ($ php_errormsg); echoconnection1is $ connection1BRn; connector; mysql_select_db (test, $ connection
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 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.