Jump to content

UPDATE remote Database from Local Database access error


Failing_Solutions

Recommended Posts

I'm trying to update our remote database from our local database here is what I have...

 

My Connections set in php file

<?php
///THIS IS THE LOCAL DATABASE
define ("DB_HOST", "xxxxx"); // set database host
define ("DB_USER", "xxxx"); // set database user
define ("DB_PASS","xxxxx"); // set database password
define ("DB_NAME","inventory"); // set database name
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection." . mysql_error());
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database" . mysql_error());

//THIS IS THE REMOTE DATABASE
define('DB_SERVER', 'xxxxx');
define('DB_SERVER_USERNAME', 'xxxxxx');
define('DB_SERVER_PASSWORD', 'xxxxxx');
define('DB_DATABASE', 'columb22_231test');
$link2 = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("Couldn't make connection." . mysql_error());
$db2= mysql_select_db(DB_DATABASE, $link2) or die("Couldn't select database" . mysql_error());
?>

 

My UPDATE QUERY update Remote Database from Local Database

<?php
$sql="UPDATE columb22_231test.products AS p 
INNER JOIN inventory.rebelrstore_inventory AS rs
ON p.products_id=rs.products_id
SET p.products_quantity = rs.products_quantity";
mysql_query($sql) or die(mysql_error());
?>

 

The error

SELECT command denied to user 'remote_xxxx'@'our.network' for table 'rebelstore_inventory'

So I'm getting a denial error to access the local database with the remote user name

 

But I am saying in my query inventory.rebelstore_inventory which should imply the local user name to kick in right??

Anybody know what I'm missing here?

 

Help very much appreciated.

 

Link to comment
Share on other sites

Because you are not specifying the link identifier in the mysql_query() statement, it is using the last connection that was created (remote.) You would need to use the following to use the local database server to run that query -

 

mysql_query($sql,$link) or die(mysql_error());

Link to comment
Share on other sites

Because you are not specifying the link identifier in the mysql_query() statement, it is using the last connection that was created (remote.) You would need to use the following to use the local database server to run that query -

 

mysql_query($sql,$link) or die(mysql_error());

 

Thanks PFMasBiSmAd

 

I had tried that, sorry I didn't post it originally, doing so does not throw an error, but does not update it either.

Link to comment
Share on other sites

If you actually are trying to execute a query that references two different database servers, it won't work. The query runs on the database server who's connection you are using and it can only reference databases and tables that server can read.

 

If you are not getting an error, it is likely that you have a database and tables with those names on the server where you are executing that query, but no matching data.

Link to comment
Share on other sites

If you actually are trying to execute a query that references two different database servers, it won't work. The query runs on the database server who's connection you are using and it can only reference databases and tables that server can read.

 

If you are not getting an error, it is likely that you have a database and tables with those names on the server where you are executing that query, but no matching data.

 

This is exactly what I was trying to do, I guess I can try and put these values into a php array then throw them at the remote database.

 

Thanks for the help

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.