The first DB is a a huge collection of data as well as being used for a very busy ecommerce site. The new application I'm building uses 3 tables from the larger Db (products) and the 2nd DB is for a 2nd completely seperate application that is in it's first version, with the potential for allot of growth.
Since the data in most ways is VERY unrelated, I thought for clarity and ease of use it would be best to keep them seperate. Mostly for future potential growth sake.
Are you using two MySQL servers or just two MySQL databases? You shouldn't need two connections to the same server if you need to access two databases on it. Simply use mysql_select_db() to move between the databases.
In my original post I showed how I was trying to use my included file to do that, to use an include wouldn't I have to have two mysql_connect()'s?
And then use the different connect variables in my mysql_db_select?
PHP wanted to use just on connection if the params for the connection were the same. When I changed the params on one of the connections, then it worked. I got the idea to try this from the manual - mysql_connect():
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters.
It seemed to me that if I didn't use different params for my second connect it would never work. To answer you question: same server two DB's.
File: db.php
<?php
// database manager
function db($database, $query) {
// main connect
$dblink = mysql_connect('localhost', 'user', 'password');
// select the preffered database using the provided variable
mysql_select_db($database, $dblink);
// fetch the results
$result = mysql_query($query, $dblink);
// close the link (if any)
mysql_close($dblink);
// return the results
return $result;
}
?>
File: index.php
<?php
// require (or include) the database file and it's function
require('db.php');
// try it out, calling the function with particular db and query.
$testdb1 = db('db1',"select * from foo where bar = 'kittythrow'");
$testdb2 = db('db2',"select * from bar where foo = 'cowthrow'");
// and so on
?>