0

I have two servers, for the sake for my questions, lets name the first server A, and the second server B. Server A is a magento server that has a lot of user data, and server B is a basic web page.

I want to create an analytics dashboard in server B, that uses the SQL databases of server A.

Now the problem is having a remote connection from server B to server A. I try to connect to server A, using this code in server B:

$servername = "104.2*****"; // Server A

$username = "root";

$password = "******";
$dbname = "magento";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

I get this error: Connection failed: Can't connect to MySQL server on '104.2******'

Can someone please tell me what I'm doing wrong?

shehzad_ucdavis
  • 135
  • 1
  • 10

2 Answers2

1

You may need to create a ssh tunnel to connect to a remote server hosted database if the settings on the database server do now allow unsecure connections which is likely why you're getting that error.

http://kb.mediatemple.net/questions/133/Tunnel+local+MySQL+server+through+SSH#gs

Vladimir Ramik
  • 1,920
  • 2
  • 13
  • 23
1

It might be that there is a firewall restriction on the server you want to connect to. The MySQL port connection might be restricted. Try to connect from the server you run this script (or another server) to the ip/port of the server you want to connect to. If you have access to a linux/windows console, try running:

telnet 104.2***** 3306

3306 is the default port for MySQL and telnet should work.

engine9pw
  • 364
  • 1
  • 5