# Error 2002 SQL

**URL:** <https://forum.infinityfree.com/t/error-2002-sql/121358>\
**Category:** Hosting Support\
**Created:** [October 15, 2026, 7:53pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358 "2026-10-15T19:53:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dev\_Morgan](https://forum.infinityfree.com/letter_avatar/dev_morgan/32/6_449c533f586939b6e5f246632a46421f.png) [@Dev\_Morgan](https://forum.infinityfree.com/u/Dev_Morgan)\
**Post date:** [October 15, 2026, 7:53pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358/1 "2026-10-15T19:53:44Z")

</div>

### Website URL

[https://ggram.golden-devs.rf.gd/testbd.php](https://ggram.golden-devs.rf.gd/testbd.php)

### Error Message

Hosting account: if0\_38891559  
MySQL host: [sql203.infinityfree.com](http://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.

### Other Information

none

---

<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:** [October 15, 2026, 7:53pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358/2 "2026-10-15T19:53:44Z")

</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:** [October 15, 2026, 7:54pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358/3 "2026-10-15T19:54:00Z")

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

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:

> [@Common MySQL Connection Errors](https://forum.infinityfree.com/docs?topic=49338):
>
> Many websites use MySQL databases to store information and settings. However, there are some reasons why the connection to the database may fail. This article describes some commonly seen error messages when connecting to a database, as well as some general tips to keep in mind when setting up a database connection. Common Error Messages Using MySQL is great, but the error message returned if there is an issue logging in to your database can be quite confusing. Here are some commonly seen error…

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.

---

<div class="post-metadata">

**Author:** ![Dev\_Morgan](https://forum.infinityfree.com/letter_avatar/dev_morgan/32/6_449c533f586939b6e5f246632a46421f.png) [@Dev\_Morgan](https://forum.infinityfree.com/u/Dev_Morgan)\
**Post date:** [October 15, 2026, 7:56pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358/4 "2026-10-15T19:56:01Z")

</div>

```auto
<?php
declare(strict_types=1);
header('Content-Type: text/plain; charset=utf-8');
try {
    $config = require \__DIR_\_ . '/config/app.php';
    echo 'PHP: ' . PHP_VERSION . PHP_EOL;
    echo 'pdo_mysql: ' . (extension_loaded('pdo_mysql') ? 'OK' : 'MISSING') . PHP_EOL;
    echo 'sessions writable: ' .
        (is_writable(\__DIR_\_ . '/storage/sessions') ? 'OK' : 'NO') .
        PHP_EOL;
    $pdo = new PDO(
        'mysql:host=' . $config\['db_host'\] .
        ';port=' . $config\['db_port'\] .
        ';dbname=' . $config\['db_name'\] .
        ';charset=utf8mb4',
        $config\['db_user'\],
        $config\['db_pass'\],
        \[
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        \]
    );
    echo 'DATABASE CONNECTION: OK' . PHP_EOL;
    $tables = $pdo->query('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN);
    $required = \[
        'users',
        'messages',
        'user_blocks',
        'user_favorites',
        'message_reactions',
        'message_hides',
        'conversation_clears',
        'conversation_pins',
        'auth_limits',
    \];
    foreach ($required as $table) {
        echo $table . ': ' .
            (in_array($table, $tables, true) ? 'OK' : 'MISSING') .
            PHP_EOL;
    }
} catch (Throwable $error) {
    http_response_code(500);
    echo 'ERROR TYPE: ' . get_class($error) . PHP_EOL;
    echo 'ERROR CODE: ' . $error->getCode() . PHP_EOL;
    echo 'ERROR: ' . $error->getMessage() . PHP_EOL;
}

```

here code to test connection, and his give me 2002 error

---

<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:** [October 15, 2026, 8:15pm UTC](https://forum.infinityfree.com/t/error-2002-sql/121358/5 "2026-10-15T20:15:36Z")

</div>

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.

[https://ggram.golden-devs.rf.gd/testdb.php](https://ggram.golden-devs.rf.gd/testdb.php)
