# PDO MySQL connection refused from hosted PHP — SQLSTATE HY000 2002

**URL:** <https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785>\
**Category:** Hosting Support\
**Created:** [November 3, 2026, 12:25pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785 "2026-11-03T12:25:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![p3-peterk](https://forum.infinityfree.com/letter_avatar/p3-peterk/32/6_449c533f586939b6e5f246632a46421f.png) [@p3-peterk](https://forum.infinityfree.com/u/p3-peterk)\
**Post date:** [November 3, 2026, 12:25pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/1 "2026-11-03T12:25:02Z")

</div>

### Website URL

[https://mshopbusiness.42web.io/](https://mshopbusiness.42web.io/)

### Error Message

SQLSTATE[HY000] [2002] Connection refused

### Other Information

Hello,

PHP hosted under account if0\_43334832 cannot connect to MySQL.

Database hostname: [sql301.infinityfree.com](http://sql301.infinityfree.com)  
MySQL port: 3306  
Database name: if0\_43334832\_db\_business  
MySQL username: if0\_43334832

A PDO connection from hosted PHP returns:

SQLSTATE[HY000] [2002] Connection refused

Please confirm:

1. Whether this MySQL hostname and port are correct.
2. Whether hosted PHP accounts on this server are permitted to connect to MySQL.
3. Whether there is a server issue or another required hostname for database connections.

The same PHP application works on local XAMPP, but the hosted setup cannot establish a MySQL connection.

---

<div class="post-metadata">

**Author:** ![system](https://infinityfree-forum-uploads.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/0/b024fd3fa88bae093c9576e55c2c94e33f890206.svg) [@system](https://forum.infinityfree.com/u/system)\
**Post date:** [November 3, 2026, 12:25pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/2 "2026-11-03T12:25:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lemni](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/lemni/32/68303_2.png) [@Lemni](https://forum.infinityfree.com/u/Lemni)\
**Post date:** [November 3, 2026, 12:25pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/3 "2026-11-03T12:25:24Z")

</div>

_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._

Your hostname and database name match what your account has: `sql301` is the MySQL host for `if0_43334832`, and `if0_43334832_db_business` is spelled exactly like the database in the control panel. So those two details aren’t the problem. I couldn’t find a source on whether port 3306 is the right one or whether any other hostname is required, so I can’t confirm either.

Another user reported the same `Connection refused` error a few weeks ago, but theirs came and went for about a minute around the same time each day. It might be the same thing, so I need to know whether yours fails on every request or only at certain times.

If it fails every time, can you post the lines of PHP that build the connection? That means the DSN and the `new PDO(...)` call, with the password removed. I’d like to check that the code uses the same host, database name and username you listed above.

Here is the other topic:

> [@Daily MySQL outage at 12:00 sharp — SQLSTATE\[HY000\] \[2002\] Connection refused](https://forum.infinityfree.com/t/daily-mysql-outage-at-12-00-sharp-sqlstate-hy000-2002-connection-refused/121371):
>
> Website URL [https://el-wassim.page.gd](https://el-wassim.page.gd)Error Message SQLSTATE[HY000] [2002] Connection refused on any query (e.g. select \* from admin\_users where id = 2 limit 1), every day around 12:00 server time, for about one minute, then recovers by itself. Seen on 11, 12, 14, 15 and 16/10/2026 (e.g. 16/10 12:00:21). DB host: [sql102.infinityfree.com](http://sql102.infinityfree.com). Other Information Credentials are unchanged and correct (works immediately before and after). This is not a max\_user\_connections (1226) error and we use no pe…

---

<div class="post-metadata">

**Author:** ![p3-peterk](https://forum.infinityfree.com/letter_avatar/p3-peterk/32/6_449c533f586939b6e5f246632a46421f.png) [@p3-peterk](https://forum.infinityfree.com/u/p3-peterk)\
**Post date:** [November 3, 2026, 2:43pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/4 "2026-11-03T14:43:54Z")

</div>

fails on every request since no connection is established

---

<div class="post-metadata">

**Author:** ![p3-peterk](https://forum.infinityfree.com/letter_avatar/p3-peterk/32/6_449c533f586939b6e5f246632a46421f.png) [@p3-peterk](https://forum.infinityfree.com/u/p3-peterk)\
**Post date:** [November 3, 2026, 2:59pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/5 "2026-11-03T14:59:05Z")

</div>

The connection fails on every request, not intermittently.  
PHP connection code:

new PDO(  
'mysql:host=[sql301.infinityfree.com](http://sql301.infinityfree.com);port=3306;

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [November 3, 2026, 9:08pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/6 "2026-11-03T21:08:28Z")

</div>

The code looks fine at first glance. But so does your website: I checked it and it seems to be working fine. Where exactly on your website is that code located?

---

<div class="post-metadata">

**Author:** ![p3-peterk](https://forum.infinityfree.com/letter_avatar/p3-peterk/32/6_449c533f586939b6e5f246632a46421f.png) [@p3-peterk](https://forum.infinityfree.com/u/p3-peterk)\
**Post date:** [November 4, 2026, 7:58am UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/7 "2026-11-04T07:58:05Z")

</div>

The connection code is located in `/htdocs/app/config/bootstrap.php`, loaded by `/htdocs/deployment-check.php`.

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [November 4, 2026, 12:26pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/8 "2026-11-04T12:26:12Z")

</div>

I hope you don’t mind, but I had a hunch and I very briefly added a `var_dump(app_config());` line to the deployment check code (it’s gone now), and it confirmed my hunch: your website configuration is not being read correctly. This is what it said for the database configuratin:

```auto
  ["database"]=>
  array(6) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["port"]=>
    int(3306)
    ["name"]=>
    string(5) "mshop"
    ["username"]=>
    string(4) "root"
    ["password"]=>
    string(0) ""
    ["charset"]=>
    string(7) "utf8mb4"
  }

```

Of course, this database host is wrong, so the database connection fails. And since the website server has no MySQL server running on it, you get a Connection Refused error.

So this is a website code bug, not a hosting issue or a database problem. Please try updating your website code so it uses the correct database configuration.

---

<div class="post-metadata">

**Author:** ![system](https://infinityfree-forum-uploads.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/0/b024fd3fa88bae093c9576e55c2c94e33f890206.svg) [@system](https://forum.infinityfree.com/u/system)\
**Post date:** [November 7, 2026, 12:26pm UTC](https://forum.infinityfree.com/t/pdo-mysql-connection-refused-from-hosted-php-sqlstate-hy000-2002/121785/9 "2026-11-07T12:26:30Z")

</div>

Closed on November 7, 2026, 12:26pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
