Jump to content

remotely access MySql DB on server A from remote Server B


inosent

Recommended Posts

I have a MySql DB located on server_a.com, properly configured, and it is accessed by a set of php pages in a folder, server_a.com/data_entry

 

server access comes through this php page as an include at the top of each php page in the folder:

 

 

<?php
$user_name="user_name";
$password="db_pass";
$database="data";
$hostname = 'data.db.1234567.hostedresource.com';
mysql_connect($hostname,$user_name,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>

 

the trick is (i think, and i cant firgure this out) in how to revise:

 

$hostname = 'data.db.1234567.hostedresource.com';

 

to somehow point to it from the remote server, that has the exact same set of php pages in a folder similarly named, i.e. server_b/data_entry

 

fwiw, the MySql is located somewhere inside the godaddy universe (the site is hosted by godaddy), but the remote server is bluehost.

 

any ideas greatly appreciated

 

TIA!

Link to comment
Share on other sites

hi, thanks for the reply

 

ok, so long as all the php files are located on server A (the local server), data entry into the MySql works great.

 

to access a MySql DB takes a user name, password, database name, and hostname, which in my case is this: $hostname = 'data.db.1234567.hostedresource.com';

 

in my case, the hostname looks like it is also showing the location of the MySql DB. so, in other words, this line of code, $hostname = 'data.db.1234567.hostedresource.com';, 'points to' the location of the MySql DB referenced.

 

When this line of code is read from a file located on server_a in the data_entry folder, i have no problems accessing the DB.

 

However, if i upload the exact same php files, with the exact same code, to a *different* server, or if it is easier to understand, a different *host*, if i try to access the MySql DB it wont work.

 

i am guessing it has to do with this line of code:

 

$hostname = 'data.db.1234567.hostedresource.com';

 

this works perfectly so long as the php file that uses that line of code is located on server_a.com

 

but i want to access that same MySql DB from server_b.com

 

the question is can that be done, and if so how to do it

 

thanks again

Link to comment
Share on other sites

Could be the MySQL server does not allow connections (for that user/password/database) from anything but server_a. For testing only stick an or die(mysql_error()) after the mysql_connect() and the mysql_select_db() (instead of what you have now) calls so you can get an error message indicating why it's not working.

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.