Can't Connect to MySQL Server on IPAddress (10061)
Check that your firewall is allowing connections through on port 3306.
Check the MySQL configuration parameter bind-address
in my.cnf
to ensure that it is allowing remote connections.
There's information and troubleshooting tips here:
http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html
According to the MySql documentation , The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.
I'm not familiar with php , but the problem might not be in your code.
If your getting the above error even after putting the Mysql port 3306 open access,
Just change bind address of mysql file my.cnf which is located at /etc/mysql/my.cnf
Update the bind address as given below
bind-address = 0.0.0.0
This will allow access to all ips remotely On AWS ec2 it is working.