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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Dale_G Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.