Prestashop 1.7.1.2数据库连接失败问题求助
Hey there, let's work through this issue step by step. It’s weird that replacing the theme folder would trigger a database connection error—usually themes don’t mess with your database credentials. But since restoring your original theme didn’t fix it, let’s focus on the most likely culprits, keeping things simple for folks who aren’t deep into PHP or databases.
1. Check your database config file (most common fix)
PrestaShop stores all its database login info in a file called settings.inc.php, which lives in your main PrestaShop folder (not the theme folder). Sometimes FTP transfers can corrupt this file by accident, even if you didn’t mean to touch it. Here’s what to do:
- Use your FTP client to download
config/settings.inc.phpto your computer. - Open it with a plain text editor (like Notepad on Windows or TextEdit on Mac—don’t use Word or other rich text editors; they’ll mess up the code).
- Look for these lines (they’ll be near the top):
define('_DB_SERVER_', 'localhost'); define('_DB_NAME_', 'your_database_name'); define('_DB_USER_', 'your_database_username'); define('_DB_PASSWD_', 'your_database_password'); - Compare these values with what you see in phpMyAdmin:
- The database name (
_DB_NAME_) is the one listed on the left sidebar when you log into phpMyAdmin. - The username (
_DB_USER_) is probably the same one you used to log into phpMyAdmin (if not, check your hosting control panel’s database section). - The password (
_DB_PASSWD_) matches the one you use for phpMyAdmin.
- The database name (
- If any values are wrong, correct them, save the file, and upload it back to your server (overwriting the old version).
2. Fix file permissions
Incorrect file permissions can stop PrestaShop from reading the config file properly. Here’s how to fix this:
- In your FTP client, right-click the
settings.inc.phpfile and select "File Permissions" or "CHMOD". - Set the permissions to
644(this means the owner can read/write, everyone else can just read). - Also check the
configfolder itself—set its permissions to755(owner can read/write/execute, others can read/execute).
3. Clear PrestaShop’s cache (even after restoring the theme)
PrestaShop caches tons of data, and old cached files can cause weird issues even after you revert the theme. Since you can’t access the admin panel, do this via FTP:
- Navigate to the
var/cachefolder in your PrestaShop root. - Delete all files and folders inside
var/cache(don’t delete thecachefolder itself, just what’s inside it). - Also head to
var/smarty/cacheandvar/smarty/compile—delete everything inside those folders too.
4. Confirm your database is working
Even though you can log into phpMyAdmin, sometimes the database server has a temporary glitch. Quick check:
- In phpMyAdmin, click your database name on the left, then go to the "SQL" tab.
- Type
SELECT 1;and click "Go". If it returns a result saying "1", your database is running fine. - If you get an error here, reach out to your hosting provider—they might need to restart the database server.
5. Restore a full site backup (if you have one)
If you made a backup before swapping the theme folder, restoring the entire site (files + database) will definitely fix this. Most hosting providers offer one-click backups in their control panel—check there first if you have a backup saved.
内容的提问来源于stack exchange,提问作者Falcon III

