Accessing multiple databases

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Accessing multiple databases

Post by mikusan »

I am making a game, the code is all mine, but it's written on an already present PHP engine namely, geeklog. Now, I take advantage of the preexisting code, but i ran into a problem. The include file i include also includes a default connection to the database.

The game i am making does not work on that database, so i made my own little:

Code: Select all

mysql_connect('localhost', '', '')
       or die("Could not connect to Database");
	
    mysql_select_db('otherdatabase') or die("Could not select database");
Nothing fancy. But i am confused as to what i have just done,
Does my little connection override the already existinig one? Will they be in conflict with each other?

I have been getting some unexpected results, but i am hoping this is due to some code flaw and not a database fight.

Thank you in advance,
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You can connect to multiple databases, e.g.
$db1 = mysql_connect(...);
$db2 = mysql_connect(...);
Just be sure to use the optional [, resource link_identifier] in the mysql_ functions to refer to the database connection you want to work with.
Post Reply