Opencart 1.5.6.4能否替换为MariaDB?故障后需修改哪些文件?
Absolutely – MariaDB is built as a drop-in replacement for MySQL, so OpenCart 1.5.6.4 can definitely run on it. The problems you’re facing are almost certainly small compatibility gaps between this older OC version and modern MariaDB/PHP setups. Let’s walk through how to resolve them step by step:
1. Update the Database Driver (Critical for PHP 7+)
OpenCart 1.5.6.4 supports both the legacy mysql extension and the newer mysqli extension. The mysql extension was removed entirely in PHP 7.0+, so if you’re running a modern PHP version with MariaDB, this is likely your core issue:
- Open both
config.php(root directory of your OC install) andadmin/config.php - Locate the line:
define('DB_DRIVER', 'mysql'); - Change it to:
define('DB_DRIVER', 'mysqli');
If your OC package doesn’t have the mysqli adapter file (system/database/mysqli.php), grab it from a standard 1.5.6.4 release – most official packages include it by default.
2. Disable Strict SQL Mode
Modern MariaDB versions enable strict SQL mode by default, which can break older OpenCart code (e.g., rejecting INSERT statements where OC expects optional fields to be left blank). To fix this:
- Open
system/database/mysqli.php(ormysql.phpif you’re still on PHP 5.x) - Find the
__constructmethod, right after the database connection is established (look for lines likeparent::__construct(...)or connection logic) - Add this line:
$this->query("SET SQL_MODE = '';");
This switches MariaDB to the looser SQL behavior that OC 1.5.6.4 was built to work with.
3. Ensure Correct Character Encoding
While MariaDB uses the same utf8 character set as MySQL, connection encoding can sometimes misconfigure, leading to garbled text or query errors. Add this line right after the SQL mode fix in the database adapter:
$this->query("SET NAMES 'utf8';");
This forces the database connection to use the utf8 encoding OC expects.
4. Fix Deprecated SQL Syntax (If Needed)
In rare cases, old MySQL-specific syntax might behave differently in MariaDB. If you get specific SQL errors, check for:
- Table creation statements using
TYPE=InnoDBinstead ofENGINE=InnoDB– OC 1.5.6.4 should useENGINEby default, but double-check your database dump if you migrated from MySQL. - Custom modules using raw
mysql_*functions – if you switched tomysqli, update these modules to use OC’s built-in database class methods ormysqli_*functions instead.
Troubleshooting Quick Tips
- Check the OpenCart error log (
system/logs/error.txtby default) – it will show exact error messages (e.g., missing extensions, SQL syntax issues) that point directly to the problem. - If you’re on a very new MariaDB version (10.5+), try setting SQL mode to
SET SQL_MODE = 'NO_ENGINE_SUBSTITUTION';instead if the blank setting causes issues.
内容的提问来源于stack exchange,提问作者Cross Vander

