Dale_G Posted August 26, 2008 Share Posted August 26, 2008 Hey everyone, basically I have two includes named 'connect.php' and 'connect2.php', they consist of the following code... $username = ''; $database = ''; $password = ''; $host = ''; mysql_connect( $host, $username, $password ); @mysql_select_db( $database ); Of course, with the proper values filled in for the respective database. When I try to include them both in a file, one of them seems to get "ignored' and the SQL queries that need that file don't work, however one of them does. I know WHY this doesn't work, I just need to know a solution so that I can include a file and can run different queries on different databases. Link to comment https://forums.phpfreaks.com/topic/121467-solved-connect-to-two-different-mysql-databases-using-two-different-connect-files/ Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 use $db1 = mysql_connect( $host, $username, $password ); $db1 will store link to one database, and you should of course have $db2 to store link to the other one. You will have to use this variables to indicate which database to use in all mysql statements. //example mysql_query($query1,$db1); mysql_query($query2,$db2); See: http://www.php.net/manual/en/function.mysql-connect.php Link to comment https://forums.phpfreaks.com/topic/121467-solved-connect-to-two-different-mysql-databases-using-two-different-connect-files/#findComment-626406 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Name the connection, and pass it as the second parameter to mysql_* functions: <?php $conn1 = mysql_connect('', '', ''); $conn2 = mysql_connect('', '', ''); mysql_select_db('foo', $conn1); mysql_select_db('bar', $conn2); $result = mysql_query("SELECT * FROM test", $conn1); //etc Link to comment https://forums.phpfreaks.com/topic/121467-solved-connect-to-two-different-mysql-databases-using-two-different-connect-files/#findComment-626407 Share on other sites More sharing options...
Dale_G Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks guys! Link to comment https://forums.phpfreaks.com/topic/121467-solved-connect-to-two-different-mysql-databases-using-two-different-connect-files/#findComment-626412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.