Jump to content

Connecting 2 databases on different hosts


aarkeys

Recommended Posts

Dear All,

 

I am having 2 different DB on 2 different hosts.

 

I am running MySQL Server on my local PC where the user is entering data in the tables. I have a website which has the identical DB on the web. I am able to connect to the database by using the codes on the server.

 

I want to update the server DB with the local system DB by running one update command. I get the error "-SELECT command denied to user 'localusername'@'localhost' for table 'pst_data'"

 

Given below is the code used for the process :

 

//connecting the remote system DB

$link = mysql_connect('IPAddress:3306', 'remoteusername', 'Password');

if (!$link) {

    die('Not connected : ' . mysql_error());

}

 

$db_selected = mysql_select_db('remotedb', $link);

if (!$db_selected) {

    die ('Can\'t use Remote System DB: ' . mysql_error());

}

 

//connecting the local database on the webstite

$weblink = mysql_connect("localhost","localusername","password");

if (!$weblink) {

    die('Not connected : ' . mysql_error());

}

$webdb_selected = mysql_select_db('localwebdb', $weblink);

if (!$webdb_selected) {

    die ('Can\'t use WebServer Database : ' . mysql_error());

}

 

//query to fetch the records from remote ystem and insert into local website database

$upd_Query=mysql_query("INSERT INTO  localwebdb.`table` SELECT * FROM  remotedb.`table` where field=' some condition' ");

---------------------------------------------------

 

I have tested that I have connected the remote DB by running queries on the webserver.

 

Could anyone bail me out so that i can copy the DB from remote to local

 

Any help would be appreciated

 

 

Link to comment
Share on other sites

Is the PHP script you are running on your PC or the remote server?

 

The error is telling you that the user "localusername" does not have permission to use the "SELECT" command.  If the script is running on the remote server, do you have a user set up on your local PC with permissions to execute your statement?

 

 

Link to comment
Share on other sites

The PHP Script is running on the server.

 

The server connects to the remote PC and i have tested it by querying the database at the remote PC.

 

I am doing the following :

1) Connecting to the remote PC - successfully connected as i can query the remote DB

2) Connecting to the DB on webserver - successfully connected

 

3) The problem occurs only when i run the query to retrieve the records from remote and update the local webserver where it denies the permission.

 

 

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.