VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/4.1-multi-database-support

⇱ Multi-Database Support | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Multi-Database Support

Purpose and Scope

This document covers Maho's multi-database architecture, which provides unified database abstraction across MySQL, PostgreSQL, and SQLite through Doctrine DBAL 4.4. The system enables developers to write database-agnostic code while supporting engine-specific optimizations through specialized adapters and configuration files.

For information about database migration scripts, see 10.6 For Model and Resource Model patterns, see 4.2 For configuration system details, see 3.3

Architecture Overview

Maho has replaced legacy database components with a modern abstraction layer. The architecture is centered around Maho\Db\Adapter\AdapterInterface, which defines the contract for all database interactions lib/Maho/Db/Adapter/AbstractPdoAdapter.php30-31

Code Entity Space to System Name Mapping

The following diagram maps the high-level system concepts to the specific classes and interfaces in the Maho codebase.

Database Abstraction Layer Mapping


Sources: lib/Maho/Db/Adapter/AbstractPdoAdapter.php30-31 lib/Maho/Db/Select.php21 lib/Maho/Db/Expr.php19

Implementation Hierarchy

Maho utilizes a driver-based approach where engine-specific logic is encapsulated in dedicated PDO adapters inheriting from AbstractPdoAdapter.

Database EngineAdapter ClassStatement Class
MySQLMaho\Db\Adapter\Pdo\MysqlMaho\Db\Statement\Pdo\Mysql
PostgreSQLMaho\Db\Adapter\Pdo\PgsqlMaho\Db\Statement\Pdo\Pgsql
SQLiteMaho\Db\Adapter\Pdo\SqliteMaho\Db\Statement\Pdo\Sqlite

Sources: lib/Maho/Db/Adapter/Pdo/Mysql.php20-34 lib/Maho/Db/Adapter/Pdo/Pgsql.php21-30 lib/Maho/Db/Adapter/Pdo/Sqlite.php19-28

Supported Database Engines

MySQL (Default)

The primary engine for Maho. It uses backticks (`) for identifier quoting and supports specific initialization like setting SQL_MODE to empty to maintain compatibility with legacy queries.

PostgreSQL

PostgreSQL support includes automatic handling of client_encoding to UTF8 and enabling standard_conforming_strings.

SQLite

Optimized for development and testing. It implements several performance-tuning PRAGMA statements upon connection and registers custom PHP functions to emulate SQL features missing in SQLite.

Query Building and Execution

Maho uses Maho\Db\Select as a query builder wrapping Doctrine's QueryBuilder lib/Maho/Db/Select.php21 The adapter is responsible for providing the underlying connection.

Select Query Data Flow


Sources: lib/Maho/Db/Select.php21 lib/Maho/Db/Adapter/AbstractPdoAdapter.php213-217

Cross-Engine Consistency Patterns

Maho enforces cross-engine parity through specific data type migrations and behavioral changes in resource models.

Timestamp to Datetime Conversion

Maho converts physical TIMESTAMP columns to DATETIME on MySQL to ensure consistency with PostgreSQL and SQLite, which do not distinguish between the two types in the same way. This also avoids MySQL's implicit timezone conversions, as Maho forces UTC at the connection level app/code/core/Mage/Core/sql/maho_setup/maho-26.5.0.php19-42

PHP-Side Timestamp Management

To achieve cross-engine parity, the MySQL-specific ON UPDATE CURRENT_TIMESTAMP clause is being phased out in favor of explicit management in PHP via _beforeSave() methods app/code/core/Mage/Catalog/sql/maho_setup/maho-26.5.0.php17-25

FeatureMySQL BehaviorPgSQL/SQLite BehaviorMaho Solution
TIMESTAMPTZ-aware, 1970-2038Same as DatetimeConvert to DATETIME app/code/core/Mage/Core/sql/maho_setup/maho-26.5.0.php42-79
ON UPDATENative supportNot supportedHandle in PHP _beforeSave app/code/core/Mage/Catalog/sql/maho_setup/maho-26.5.0.php17-25

Transaction Management

The AdapterInterface and AbstractPdoAdapter provide platform-agnostic transaction control.

CLI Database Tools

Maho provides CLI commands for direct database interaction that support all three engines.

Sources:

  • lib/Maho/Db/Adapter/AbstractPdoAdapter.php
  • lib/Maho/Db/Adapter/Pdo/Mysql.php
  • lib/Maho/Db/Adapter/Pdo/Pgsql.php
  • lib/Maho/Db/Adapter/Pdo/Sqlite.php
  • app/code/core/Mage/Core/sql/maho_setup/maho-26.5.0.php
  • app/code/core/Mage/Catalog/sql/maho_setup/maho-26.5.0.php
  • lib/MahoCLI/Commands/DBConnect.php
  • lib/MahoCLI/Commands/DBQuery.php