1

I'm kinda new in web development and i'm facing this problem with a remote server.

I can connect with MySQL in the remote server via SSH, using the the remote server's domain and everything works fine but for some reason it doesn't work on my php files.

This is my conection code:

$servername = "domain_name";
$username = "user";
$password = "password";
$database = "db_name";
$port = 3306;

// Create connection
$conn = new mysqli($servername, $username, $password, $database, $port);

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

But the only thing i get in my file is:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'DOMAIN' (111)

As a sidenote i've tried:

-using the ip address of the server instead of the domain name

-changing the port to 3307

How can i fix it?

Also, i don't have access to the server itself

  • 5
    Your PHP files are not using SSH to connect remotely like you are doing. They're relying on the MySQL instance to be configured for remote access in the my.cnf file on the server. I have explained how to remotely connect to MySQL here: http://stackoverflow.com/questions/15663001/remote-connections-mysql-ubuntu/15684341#15684341 – apesa Oct 02 '15 at 17:16

0 Answers0