1

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.
OlivierH
  • 3,875
  • 1
  • 19
  • 32
CDubYaa
  • 45
  • 1
  • 10
  • I think the `xxxxxx` part in your MySQL Host needs to be replaced with the actual value. – Amal Murali Dec 23 '13 at 13:01
  • 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 Dec 23 '13 at 13:01
  • @AmalMurali GoDaddy shared hosting strips out sensitive/resolved hostname/user information like that. – Mike B Dec 23 '13 at 13:09
  • xxxxxx is just a value I have used to block out my actual db name. I have the correct info there. – CDubYaa Dec 23 '13 at 13:19
  • 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 Dec 23 '13 at 13:21

2 Answers2

4

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.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • I had this issue a while back, whilst trying to connect to 3306 via Navicat. I was running the cPanel interface then, so I had a GUI to follow, and this worked. +1 – ʰᵈˑ Dec 23 '13 at 13:09
0

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);
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78