I want to connect with external database using PHP
. But, it gives this error
Warning: mysql_connect(): Can't connect to MySQL server on 'SERVER_IP_ADDRESS' (110) in /home/<username>/public_html/index.php on line 7
Can't connect to MySQL server on 'SERVER_IP_ADDRESS' (110)
Here is my code.
define("_CONFIG_DB_HOST", "SERVER_IP_ADDRESS"); /* database host name */
define("_CONFIG_DB_NAME", "DATABASE_NAME"); /* database name */
define("_CONFIG_DB_USER", "DATABASE_USERNAME"); /* database username */
define("_CONFIG_DB_PASS", "DATABASE_PASSWORD"); /* database password */
$con = mysql_connect(_CONFIG_DB_HOST,_CONFIG_DB_USER,_CONFIG_DB_PASS) or die(mysql_error());
mysql_select_db(_CONFIG_DB_NAME,$con) or die(mysql_error());
I've also added entry for Remote Database Access Hosts
in Host Server
Please guide me if I'm doing anything wrong.
Make sure DATABASE_USERNAME
has access from you host (the machine running this script) has access to DATABASE_NAME
on SERVER_IP_ADDRESS
.
When you grant access on database to use you would use USERNAME@HOST
form. Here the HOST
means the host where this USERNAME
would be connecting from. Usually we keep it localhost . becasue we want to connect by a user who is in localhost according to mysql server. But your local host is not mysql servers localhost. That's why that host part needs to be changed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.