0

I'm using cPanel on godaddy for my website, and my php script connects to the db of my dedicated server.

$servername = "hostip";
$username = "root";
$password = "pw";
$dbname = "dbname";
$port =  "port";
$mysqli = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$mysqli) {
    die("Connection failed: " . mysqli_connect_error());
}
?>

when I deploy the website in my localhost, and my friend's pc which is in different country, it connects to the db and everything works just fine, however when I deploy it in godaddy cPanel, I get this error. Connection failed: Can't connect to MySQL server on 'ip' (111). I tried whitelisting the IP, checked firewall, but can't seem to find solution. I'm using mariaDB 5.5 for my server can anyone help? :(

noobcoder
  • 3
  • 1
  • 2
    Are you sure you are setting `$servername` properly? `hostip` doesn't look like a valid address. – Camilo Nov 01 '20 at 04:08
  • 2
    Is it connecting to a remote IP or a localhost IP? – PHP Guru Nov 01 '20 at 04:12
  • For Godaddy, the db server is normally "localhost" (unless you are connecting to a remote host db server). So please try changing to $servername = "localhost" and then retry. – Ken Lee Nov 01 '20 at 04:14
  • @Camilo no im using the actual IP of course.. that is just to show what I did – noobcoder Nov 01 '20 at 04:36
  • @PHPGuru its connecting to remote IP – noobcoder Nov 01 '20 at 04:36
  • @KenLee I need to connect to remote host db... so localhost would work (and it did) but thats not what I need.. – noobcoder Nov 01 '20 at 04:37
  • If you are connecting to remote IP, make sure you set the target db server to accept remote connection. – Ken Lee Nov 01 '20 at 04:40
  • @KenLee it is allowing.. I stated if I deploy website on my pc or my friends pc it connects to db no problem – noobcoder Nov 01 '20 at 04:44
  • Please make sure you have set Godaddy to allow external db connection: Go to your GoDaddy product page. In the cPanel Home page, in the Databases section, click Remote MySQL. Under Add Access Host, in the Host field, enter the IP address from which you want to access your databases – Ken Lee Nov 01 '20 at 05:37
  • @KenLee I dont know how to stress this enough, but I'm NOT using the database in godaddy. I'm using the database which is located in different place. But still, I have added it in remote mysql long time ago still doesnt work. I need the cPanel to connect to external DB not the other way around – noobcoder Nov 01 '20 at 07:43

0 Answers0