Hi, How do I connect 2 mysql database in a single php program? What I want to do is, 1 database will be the main database, while the other one will be a dummy database. Seems, the usual way to connect to the database don't work. Any help is appreciate.
Yeah similar to the one that you've shown. For database 1 : $con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Database ERROR ""); mysql_select_db(DB_NAME,$con) or die ("ERROR: Database not found "); Code (markup): For database 2: $con1 = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Database ERROR ""); mysql_select_db(DB_NAME1,$con1) or die ("ERROR: Database not found "); Code (markup): But when I call the database, it only connect to the 2nd database and not both.
i was not allowed to post link =( do a search using google : connect to two database sql u wil see some topics on this good luck
Note to anyone reading this thread. I have a typo in my code. There is an extra ". As long as all the table names and variable are different I would think that should work. EDIT: I did a little research. As I seem to read it you need to call specific tables when connecting to more than one at the same time. The articles for your reading: http://www.webmasterworld.com/php/3221902.htm http://www.phpbuilder.com/board/archive/index.php/t-10220835.html The Google search string that yielded the results
if you not yet solve this problem... here is the solution: everytime you're using mysql function .. such as mysql_query() ... always include the connection identifier.. example: mysql_query($sql, $con) --- for 1st db mysql_query($sql, $con1) --- for 2nd db solved!!