Is your SMM Panel showing a “Database Connection Error”?
You successfully installed the script, but when you try to load the page, you see a white screen with this fatal error message:
SQLSTATE[HY000] [2002] Connection refused
Or sometimes:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
This is the most frustrating error for freelance developers. It usually happens when you move your script to a new hosting provider (like moving from cPanel to CyberPanel or VPS).
![How to Fix SQLSTATE[HY000] [2002] Connection Refused in SMM Scripts](https://ajtaktime.uk/wp-content/uploads/2026/01/How-to-Fix-SQLSTATEHY000-2002-Connection-Refused-in-SMM-Scripts-1024x414.png)
In this guide, I will show you the 3-minute fix that works for 99% of SMM scripts (SmartPanel, PerfectPanel, and custom PHP scripts).
Why This Error Happens
This is not a bug in your script code. It is a configuration mismatch between your script and the server.
The error code [2002] Connection refused means your PHP script is trying to knock on the database’s door, but the server is not opening it.
This usually happens because:
- You are using
localhostbut the server expects an IP address. - Your database user does not have the right permissions.
Fix #1: Change Localhost to IP (The Magic Fix)
Most SMM scripts have a config.php or database.php file inside the app/ or admin/ folder.
Inside, you will see a line defining the host.
PHP
define('DB_HOST', 'localhost');
On modern servers (especially those using Docker or CyberPanel), “localhost” tries to connect via a UNIX socket, which might be disabled.
The Solution: Change localhost to the local loopback IP address.
PHP
define('DB_HOST', '127.0.0.1');
Save the file and refresh your website. For 80% of users, the site will load immediately.
Fix #2: Check Your Database Credentials
If Fix #1 did not work, check your username and password.
Go to your config.php file again. Ensure there are no extra spaces in the password.
PHP
// Make sure there are no spaces inside the quotes
define('DB_USER', 'net_hussnain');
define('DB_PASS', 'CorrectPassword123');
Pro Tip: If your password contains special symbols like # or $, put the password inside single quotes ' ' instead of double quotes " " to avoid PHP parsing errors.
Fix #3: Grant User Privileges
Sometimes, you created the database and the user, but you forgot to link them.
- Go to cPanel > MySQL Databases.
- Scroll down to “Add User to Database”.
- Select your User and your Database.
- Click Add.
- Important: On the next screen, check “ALL PRIVILEGES” and click “Make Changes”.
Without “All Privileges”, the script cannot write data, and the connection will be refused.
What To Do After The Site Loads?
Once your database connects, your site will open. However, because you are likely on a new server with PHP 8.2, you might suddenly see new warning messages on the screen.
If you see errors like “Warning: Undefined array key”, do not panic. This is common after fixing the database.
Read Next: How to Fix “Undefined Array Key” Warning in PHP 8.2 SMM Scripts
Follow that guide to clean up your code and make your panel error-free.
Professional Web Developer & SMM Script Expert since 2017. Fixing bugs and helping freelancers build secure websites.