php - My code only connect to localhost mysql server but not for remote server -
when trying connect remote mysql server error :
php_network_getaddresses: getaddrinfo failed: hôte inconnu.
(translation: host unknown
).
con.php :
<?php $db_host = 'http://xxx.xxx.xxx.xxx'; $db_username = 'xxx'; $db_password = 'xxx'; $db_name = 'xxx'; $con = mysql_connect($db_host,$db_username,$db_password); $select_db = mysql_select_db($db_name,$con); ?>
when connecting localhost goes fine, remote connection didn't work.
you cannot connect mysql using http protocol (namely because of port conflicts). parameter should ip string. remove http
protocol follows:
$db_host = 'xxx.xxx.xxx.xxx'; $db_username = 'xxx'; $db_password = 'xxx'; $db_name = 'xxx'; $con = mysql_connect($db_host, $db_username, $db_password); $select_db = mysql_select_db($db_name, $con);
you should note mysql can configured prevent other localhost
access on user accounts. ensure user you're using able access database domain.
finally, mysql_*
family of functions being deprecated, , should avoid using them new code. instead, check out mysqli or pdo.
Comments
Post a Comment