nomanoma Posted May 18, 2009 Share Posted May 18, 2009 hi: i want to connect different databases on different hosts. but i can't do it. i can only connect to those on my hosting. here's what i'm using: <?php $partnercount ="8"; $supersolositename = "ultimateworldwide"; // small letters no spaces $partner1 = "Ultimateworldwide"; // home website name - first letter caps // file in Connect folder should match partner name for example if partner // name is Mighty then the partners file in the Connect folder should be // Mighty.php $partner2 = "Dragonballz"; // partner website name leave empty if not in use $partner3 = "Easystreetads"; // partner website name leave empty if not in use $partner4 = "Rockintextads"; // partner website name leave empty if not in use $partner5 = "Mightyadz"; // partner website name leave empty if not in use $partner6 = "Timelesstextads"; // partner website name leave empty if not in use $partner7 = "Twilightadz"; // partner website name leave empty if not in use $partner8 = "Ultratextads"; // partner website name leave empty if not in use ?> and this is a sample of the connect files: <?php $MySqlHostname = "206.221.189.3"; //the name of your host - if its local leave it as is. $MySqlUsername = "username"; //the username to your database. $MySqlPassword = "pass"; //the password to your database. $MySqlDatabase = "db"; //the name of your database. // do not edit below this line!! /////////////////////////////////////////////////////////////////////// $dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) or die("Could not connect to database"); @mysql_select_db("$MySqlDatabase") or die( "Could not select database"); ?> thank you Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/ Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 Why can't you do it? Did you get errors? If so, what are they? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-836933 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 die("Could not connect to database") Useless. Use this instead die(mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837024 Share on other sites More sharing options...
nomanoma Posted May 19, 2009 Author Share Posted May 19, 2009 i can only connect to those on my host but not the ones on the other hosts. here's the error: Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '174.133.3.162' (4) in /home/mightyad/public_html/Connect/Rockintextads.php on line 12 Could not connect to database and that connect file is the same as the one i posted earlier up. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837084 Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 some servers alot of them have set there mysql config file to not except connections from other servers. I had this issue it will say unable to connect. This was realy annoying because i wanted to develop facebook stuff, you need to contact your sys admin. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837127 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 First matter is if your hosting (where your script runs) allows you to try a mysql remote connection. If it does, second matter is if mysql remote server allows remote connections. This is usually not, on your average hosting service. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837130 Share on other sites More sharing options...
nomanoma Posted May 19, 2009 Author Share Posted May 19, 2009 i contacted my host and made them enable remote access. and i added the ips to the other sites i'm trying to connect to at their remote mysql. what else can i do? am i supposed to use different ips than those of the shared hosting ip servers? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837149 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 and i added the ips to the other sites i'm trying to connect to at their remote mysql. ????? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837150 Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 i contacted my host and made them enable remote access. and i added the ips to the other sites i'm trying to connect to at their remote mysql. what else can i do? am i supposed to use different ips than those of the shared hosting ip servers? they havent set it up properly look at the error message ??? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837151 Share on other sites More sharing options...
nomanoma Posted May 19, 2009 Author Share Posted May 19, 2009 for luca: i added my server ip to their allowed hosts list and vice versa that's what i meant. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837156 Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 for luca: i added my server ip to their allowed hosts list and vice versa that's what i meant. nah they have a config for myslq in the ini Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837157 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 I don't know what you mean by "their allowed hosts list"... anyway, let's say your script runs on host A and your target mysql server is on host B. These are the conditions you need to match: - Host A must allow you to try a mysql remote connection - Host B must allow mysql remote connections - Mysql server on host B must have a remote user defined that matches Host A address and, of course, you must know and use this user's credentials. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837167 Share on other sites More sharing options...
nomanoma Posted May 19, 2009 Author Share Posted May 19, 2009 - Mysql server on host B must have a remote user defined that matches Host A address what does that mean? how can i do that exactly? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837300 Share on other sites More sharing options...
luca200 Posted May 19, 2009 Share Posted May 19, 2009 - Mysql server on host B must have a remote user defined that matches Host A address what does that mean? how can i do that exactly? Mysql server on host B must be given the following command (for example): GRANT ALL PRIVILEGES ON yourdb.* to yourUsername@yourIP identified by 'yourPassword'; Where 'yourIP' can be 'yourHostName' (meaning Host A's hostname) or even "yourUsername@%" (meaning that you can use that username from every remote host). But the main question is: are you the Mysql server on host B's administrator? If you're not, forget you can do this! Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837319 Share on other sites More sharing options...
nomanoma Posted May 19, 2009 Author Share Posted May 19, 2009 ok bear with me please. i'm making separate connect files to each site i want to connect to. in each connect file i'm using the original user and password assigned to each database (on their host) for example: site B: ip: B, userB, PasswordB, dbnameB site C: ip: C, userC, PasswordC, dbnameC are you saying that i need to make only 1 user and password and assign it to all sites? Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-837474 Share on other sites More sharing options...
luca200 Posted May 20, 2009 Share Posted May 20, 2009 are you saying that i need to make only 1 user and password and assign it to all sites? No. I'm not saying that. As far as you get "Can't connect to MySQL server on....", it's not a matter of user or password. Did you fix the first two points I posted before? - Host A must allow you to try a mysql remote connection - Host B must allow mysql remote connections Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-838390 Share on other sites More sharing options...
nomanoma Posted May 22, 2009 Author Share Posted May 22, 2009 i allowed all ips on all hosts firewall. now i can get my sites to connect to theirs. the problem now is that they can't connect to mine. i get another error: Warning: mysql_connect() [function.mysql-connect]: Access denied user 'famousad_nomanom'@'tweety.zoothost.com' in /home/rockinex/public_html/Connect/Twilightadz.php on line 12 Could not connect to database help Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-840052 Share on other sites More sharing options...
fenway Posted May 22, 2009 Share Posted May 22, 2009 Then it's the wrong password. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-840189 Share on other sites More sharing options...
nomanoma Posted May 22, 2009 Author Share Posted May 22, 2009 no it's not. i'm sure of the username and password. the problem is it says 'famousad_nomanom'@'tweety.zoothost.com' where this is not my host. this is the other site that is trying to connect to my site host. i don't know why this is happening. i'm using this code: <?php $MySqlHostname = "174.120.1.53"; //the name of your host - if its local leave it as is. $MySqlUsername = "famousad_nomanom"; //the username to your database. $MySqlPassword = "pass"; //the password to your database. $MySqlDatabase = "famousad_twilight"; //the name of your database. // do not edit below this line!! /////////////////////////////////////////////////////////////////////// $dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) or die("Could not connect to database"); @mysql_select_db("$MySqlDatabase") or die( "Could not select database"); ?> i don't know why it uses her host ip and not the one i wrote. on the other hand i'm using same connect files (with their usernames and pass and host ips) and it's working on my sites only. help please. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-840265 Share on other sites More sharing options...
luca200 Posted May 24, 2009 Share Posted May 24, 2009 i don't know why it uses her host ip and not the one i wrote. I'm afraid you're misunderstanding the matter. Let's say your script on site A tryes to connect to host B's mysql server: n your script you'll write "host B" as mysqlhostname. The mysql server on host B will get a connection request from "youruser@hostA" I guess tweety.zoothost.com is the host where your script is running. The matter now is as I posted before: you have to define a user on host B's mysql as 'famousad_nomanom@tweety.zoothost.com'. Did you do it? I guess not. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-841356 Share on other sites More sharing options...
nomanoma Posted May 28, 2009 Author Share Posted May 28, 2009 luca you are confused. "Let's say your script on site A tryes to connect to host B's mysql server: n your script you'll write "host B" as mysqlhostname." that's exactly what i did but what i get is the wrong host (different that the one i'm wrote on the script). of course i made the right users and of course i gave access to that user and allowed the ips to my remote mysql and firewall. so whatever you said before doesn't apply to this problem. Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-844385 Share on other sites More sharing options...
luca200 Posted May 29, 2009 Share Posted May 29, 2009 what i get is the wrong host How do you know that? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/158656-solved-connect-different-databases-on-different-hosts/#findComment-844796 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.