1
votes

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.
2
I think the xxxxxx part in your MySQL Host needs to be replaced with the actual value. - Amal Murali
does the web server you are connecting from have permission to connect to the target sql database server? did you create a db user with % for the host? - Latheesan
@AmalMurali GoDaddy shared hosting strips out sensitive/resolved hostname/user information like that. - Mike B
xxxxxx is just a value I have used to block out my actual db name. I have the correct info there. - CDubYaa
Lathesan, not sure what you mean. I am using this exact same code on one site and everything connects just fine. I have not changed permissions on the site where the mysql server is. When I have put the files in another host it is not connecting. - CDubYaa

2 Answers

4
votes

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.

0
votes

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);