Hosting account: if0_38891559
MySQL host: sql203.infinityfree.com
Database: if0_38891559_ggram
PHP 8.4.25 with PDO MySQL is running inside the same InfinityFree
hosting account, but the connection returns:
SQLSTATE[HY000] [2002] Connection refused
The hostname and database credentials were copied directly from
the MySQL Databases page. Please check internal connectivity,
firewall rules and account mapping between my hosting account
and the sql203 MySQL server.
Welcome to the InfinityFree community forum! Good to have you here.
Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
Solving an issue is a joint effort. Try the suggestions you get and report back what happened.
Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.
Could you post the part of testbd.php that builds the connection (the DSN, host, port and username, with the password removed)? Could you also say whether you can open the database in phpMyAdmin from the control panel? If phpMyAdmin works, the database server is up and the problem is in the connection details your script uses. If it fails too, that points at the server side, and a person would need to look at it.
I couldn’t find an answer for [2002] Connection refused from a script inside a hosting account. The only topics I found were about external databases or other setups, so they may not be the same problem. The nearest source is the article on common connection errors. It says the hostname must be the one shown under MySQL Databases, not localhost, and that the password is the hosting account password, not the members area one:
Your account’s database server does match sql203. So the next thing to check is whether the script sends exactly what the control panel shows, for example a custom port or a different host string in the DSN.
I had a hunch, so I hope you don’t mind that I added an extra line to the testdb.php script, which shows the contents of the $config['db_host'] parameter.
When you run the page now, you’ll see that the actual host used is 127.0.0.1, not sql203.infinityfree.com.
So that’s why the database connection fails: you’re connecting to the wrong host. So you’ll need to fix that to be able to connect to your database from your website.