CDubYaa
CDubYaa

Reputation: 45

mysqli connection error across servers using php

I am trying to connect to MySQL database which is on another server using PHP connection. I am getting the following error and can not figure it out.

This is the error when I include the port:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'xxxxxx.db.0000095.hostedresource.com:3306' (25) in /home/xxxxxx/public_html/tools/include/db_connect.php on line 3 Failed to connect to MySQL: Unknown MySQL server host 'xxxxxxxx.db.0000095.hostedresource.com:3306' (25)


This is my error when not using the port:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003): Unknown MySQL server host 'xxxxxx.db.0000095.hostedresource.com' (110) in /home/xxxxxx/public_html/tools/include/db_connect.php on line 3 Failed to connect to MySQL: Unknown MySQL server host 'xxxxxxxx.db.0000095.hostedresource.com' (110)


This is my db_connect file:

<?
$con=mysqli_connect("xxxxxx.db.0000095.hostedresource.com","xxcorrectxx","xxcorrectxx",
"xxcorrectxx");

if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>


Is this a possible firewall issue on the server I have the include file on? This db connect file is working fine on other domains I have. Please tell me if you can see a fix for this. Thank you.

Upvotes: 1

Views: 3827

Answers (2)

Gerald Schneider
Gerald Schneider

Reputation: 17797

According to the documentation of mysqli_connect() the port is an additional parameter.

$con=mysqli_connect("xxxxxx.db.0000095.hostedresource.com",
  "xxcorrectxx","xxcorrectxx", "xxcorrectxx", 3306);

Upvotes: 0

Raptor
Raptor

Reputation: 54212

The traffic is blocked by firewall, probably.

Normally MySQL port is NOT open to public access; it is available for local network only. Moreover, the DB user is probably having localhost or an IP instead of any host ( % ) in the MySQL user permission table.

You can verify by telnet to 3306 port in the remote server.

Upvotes: 4

Related Questions