I am having trouble connecting to MySQL with PHP PDO on my InfinityFree account. I am using the following code:
$dbh = new PDO(mysql:host=sqlxxxx. infinityfree.com;dbname=my_user_helpdesk;port=3306, my_user, my_pass)
I have tried using both “sqlxxxx. infinityfree. com” and “sqlxxxx. byetcluster .com” as the host, and I have also tried using the username and password that I have listed in my InfinityFree dashboard. However, I am still unable to connect to the database.
Sometimes, I do not get any error message, but other times I get the following error:
PHPphp_network_getaddresses: getaddrinfo for my_user failed: Name or service not known
Other Information
(other information and details relevant to your question)
I’m not sure since you’re not sharing the actual values, but it seems you keep a space between the dot and the infinityfree.com part of the domain, as also shown here:
Would it be possible to share your actual values, redacting only the password? You’ve already shared your username and dbname, so showing the SQL URL in the code exactly as it is shouldn’t be an issue.
Take a look at this article too if you haven’t already:
Since your domain does not start with epiz_, perhaps you want to use the infinityfree.com domain? You’ve mentioned that you tried it before, so was epizy left from a previous test?
I tried with differents hostname, my real host in the dash is sql113.infinityfree.com
but if i put it or oder like “sqlxxxx. infinityfree. com” and “sqlxxxx. byetcluster .com” have the same problem
and going into the else
else{
var_dump($dbh);
echo 'No se ha podido conectar';
die();
}
This sounds to me like your code is trying to use the username as the database hostname. Please make sure to place the MySQLi connect parameters in the right order. It’s supposed to be $hostname, $username, $password, $database.