I am trying to make a webapp using PHP and MySQL in backend. I want to know that how can I use two MySQL servers to fetch data. Because I am going to use two domains for apps. So when my first sql database will get to its limit, I will need to use another server. So how can I fetch data from all servers? I am gonna use user signup and login system and then other their document information and all. So any suggestion for me? Do you think that I should use user details on a single server and other details of documents on another server?
My question might be confusing so let me try to explain more.
See, I am going to use two domains. Domain1 and Domain2
People will be able to register from both domains to access both apps. (like google's apps e.g. gmail, youtube, adsense, adwords and all)
Domain1 will make shorten urls, Domain2 will allow to manage files. And also Domain2 will generate shorten link to download those files. so people can upload files from Domain1 and it will generate shorten urls like Domain1/f/123456. Something like that, so any suggestion for apps?
You can easily use one database from two (or many more) apps. You just need the host name to access the database from anywhere. For example if your database host is whatever.secureserver.net just put that in the connection parameters like so:
$connection = mysql_connect('whatever.secureserver.net', 'username', 'password');
You can do that in two three, four ..etc. different apps accessing the same database. You do however have to make sure that the database allows remote connections if the apps are remote in relation to the database.
If you want to use two databases (db1 and db2 in this example) in one app you can do the following -
If the databases are on the same server:
$connection1 = mysql_connect('whatever.secureserver.net', 'username', 'password');
$db1_selected = mysql_select_db('db1', $connection1);
$db2_selected = mysql_select_db('db2', $connection1);
If the databases are on different servers:
$connection1 = mysql_connect('whatever.secureserver.net', 'username', 'password');
$connection2 = mysql_connect('somethingelse.secureserver.net', 'username', 'password');
$db1_selected = mysql_select_db('db1', $connection1);
$db2_selected = mysql_select_db('db2', $connection2);
There is a more elegant way of handling database connections of course but I chose this verbose answer so it is plainly spelled out for you.