Can you connect to a host DB from within another?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can you connect to a host DB from within another?

Post 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???
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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)".
(#10850)
Post Reply