Authentication issue

Website URL

https://izina3link.wuaze.com

Error Message

Hosting account: if0_43113193
MySQL host: sql305.infinityfree
Database: if0_43113193_izinaerp
Database username: if0_43113193
My PHP application cannot connect to MySQL.
The exact error is:
SQLSTATE[HY000] [2002] Connection refused
I verified the following:

  • The database exists and is accessible through phpMyAdmin.
  • The database tables and data are present.
  • The PHP application is hosted inside the same InfinityFree hosting account.
  • The database hostname, database name, and username match the values shown in the InfinityFree control panel.
  • I tested both sql305.infinityfree.com and sql305.byetcluster
  • Both return Connection refused.
  • This is not an Access denied or wrong-password error.
    Could you please check whether hosting account if0_43113193 can connect internally to MySQL server sql305, and whether there is a database networking/firewall/backend issue affecting this account?

Other Information

sql305.infinityfree.com

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.

Can you paste the MySQL hostname exactly as your control panel lists it under MySQL Databases? Can you also share the lines of your PHP code that build the connection, with the password removed? I’d like to see the host value and whether a port is set. Your post gives the host a few different ways (sql305.infinityfree, sql305.infinityfree.com, sql305.byetcluster). I can’t tell from that which one your code actually uses.

The knowledge base says the hostname has to be used exactly as listed under Current Databases, and that localhost won’t work on InfinityFree. It also says a connection error that doesn’t say much usually comes from the details your software passes, so the exact code is the quickest way to narrow it down:

The forum topics I found with the same “Connection refused” error were mostly scripts pointing at a database somewhere else (an external Aiven database, for instance). Yours doesn’t look like that, so I wouldn’t assume it’s the same cause. I found nothing that says what “Connection refused” means from an InfinityFree database server itself. If the hostname and code both match what the control panel shows, a person would need to look at the server side.

The MySQL hostname shown in my InfinityFree control panel under MySQL Databases is:

sql305.infinityfree.com

My current .env configuration is:

DB_HOST=sql305.infinityfree.com
DB_PORT=3306
DB_NAME=if0_43113193_izinaerp
DB_USER=if0_43113193
DB_PASSWORD=

The application uses PDO. The database connection is built in _private/src/Bootstrap.php like this:

function db(): PDO {
    static $pdo = null;

    if (!$pdo) {
        $dsn = sprintf(
            'mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4',
            config('DB_HOST', '127.0.0.1'),
            (int) config('DB_PORT', '3306'),
            config('DB_NAME', 'izina_erp_v1')
        );

        $pdo = new PDO(
            $dsn,
            config('DB_USER'),
            config('DB_PASSWORD'),
            [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES => false
            ]
        );
    }

    return $pdo;
}

So the resulting DSN is effectively:

mysql:host=sql305.infinityfree.com;port=3306;dbname=if0_43113193_izinaerp;charset=utf8mb4

I also created a minimal PDO connection test on the same InfinityFree hosting account. It returned:

SQLSTATE[HY000] [2002] Connection refused

Welcome to the forum. Just checking, because I’m not 100% confident on the code, your not trying to connect to the database on 127.0.0.1 are you? Because that won’t work.

I may be totally off base here, so if I’m wrong, please feel free to disregard the above

My guess is that config() did not actually got values from your .env file, and is falling back to default values.

Try to make the code actually print the DSN out to see if it is wrong, not the “effectively something” you may have guessed.