Page 1 of 1

Can you connect to a host DB from within another?

Posted: Thu Oct 25, 2012 5:50 am
by simonmlewis
We have a web site for products, and want to "sell similar" on one of our other web sites; same product name, photos etc.

So we want to click a link and select which of the two web sites it's going to, and then submit to post the data collected, to that remote database.

I thought it would be as similar as doing a db connection to the IP Address, username, password and DBName, but during a test to simple extract data from that site, from within the other site, it freezes.

The external site has the "receiving" site's IP whitelisted.

Could it just be down to a Firewall on the host site, not allowed external or internal connections from another web site DB? And if so, how does it work with Google Ads???

Re: Can you connect to a host DB from within another?

Posted: Thu Oct 25, 2012 12:14 pm
by Christopher
You don't say what kind of database you are using. If it is MySQL then you will need to grant access to the database from an external IP.

Re: Can you connect to a host DB from within another?

Posted: Fri Oct 26, 2012 5:58 am
by simonmlewis
It is MySQL.

Code: Select all

<?php
$cookietype = $_COOKIE['type'];
if ($cookietype == "admin")
{
include "dbconnIE.php";

 $result = mysql_query ("SELECT * FROM products WHERE id = '519'");
	while ($row = mysql_fetch_object($result))
      {
      echo "$row->title";
      }
			mysql_free_result($result);
			mysql_close($sqlconn);
			}
			?>
I wonder, is the problem because I am using a generic "SELECT * FROM PRODUCTS"? when I am connecting to an external DB?

I've been told the connections are working.

[text]Warning: mysql_query() [function.mysql-query]: Access denied for user 'site'@'localhost' (using password: NO) in /home/site/public_html/includes/a_testielink.inc on line 7[/text]

I get this error.
So I am wonder if this is because it is trying a "current" connection rather than the new connection?

Re: Can you connect to a host DB from within another?

Posted: Fri Oct 26, 2012 11:00 am
by Christopher
SQL is SQL whether it is to a local or remote database. Check you connection credentials and that the user you are using is GRANTed rights on the remote database. The problem is this "Access denied for user 'site'@'localhost' (using password: NO)".