Hi all,
I'm after some advice. I am reasonable with php mysql but not great. What I have is a quickly growing project and database size limitations (Host driven).
What I would like to do is to use two databases. At the moment I use one for all the users and photo galleries but I'd like to use a different one for the next bit of the project.
My question is can I have two running together.
If I have two comm includes at the start of the file will mysql just find the correct table from my queries.
I hope I have explained this well enough but I'm not certain. If you need any more help let me know.
Multiple mysql databases
Moderator: General Moderators
-
webmonkey88
- Forum Newbie
- Posts: 20
- Joined: Fri Aug 14, 2009 4:30 am
Re: Multiple mysql databases
from what i have just quickly read here : http://uk3.php.net/mysql_select_db
The mysql_query() will work on the currently selected database, if you have one user who can access both database you could from my understanding of what i have just read(not done this personally) change between the two databases with mysql_select_db(), this should enable you to work with both databases.
The mysql_query() will work on the currently selected database, if you have one user who can access both database you could from my understanding of what i have just read(not done this personally) change between the two databases with mysql_select_db(), this should enable you to work with both databases.
Re: Multiple mysql databases
You can connect to as many databases as you like (up to whatever the number of connections your server is limited to is).
Code: Select all
$connection_1 = mysql_connect("localhost","bob","password");
mysql_select_db($connection_1,"shop");
$connection_2 = mysql_connect("localhost","fred","password");
mysql_select_db($connection_2,"office");
$connection_3 = mysql_connect("localhost","alice","password");
mysql_select_db($connection_3,"warehouse");
$result_from_shop_database = mysql_query("select * from table", $connection_1);
$result_from_office_database = mysql_query("select * from table", $connection_2);
$result_from_warehouse_database = mysql_query("select * from table", $connection_3);