Jump to content

[SOLVED] connect different databases on different hosts


nomanoma

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

- 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!

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.