I'm trying to access a database remotely. I am able to access it from the server itself, but I need to access it remotely and am doing that using XAMPP on my computer.
I've added the possibility for the database user to access the database from my ip (also tried using %). Here is the code:
$servername = $websiteIP; //e.g. xx.xx.xxx.xxx, also tried website URL and URL to phpMyAdmin
$username = 'username';
$password = 'password';
$dbname = 'dbname';
$port = '3306';
$conn = new mysqli($servername, $username, $password, $dbname);
// also tried $conn = new mysqli($servername, $username, $password, $dbname, $port);
But I always get this error:
Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in ...
except when I use $servername = $urlToMyPhpAdmin; Then I get this error:
Warning: mysqli::mysqli(): MySQL server has gone away in xxx on line 10. Warning: mysqli::mysqli(): Error while reading greeting packet. PID=102448 in xxx on line 10. Warning: mysqli::mysqli(): (HY000/2006): MySQL server has gone away in xxx on line 10
What am I missing?