Doctrine DBAL
A PHP database abstraction layer with a fluent query builder and schema introspection across major RDBMS engines
Repository Health
Technical Analysis
Doctrine DBAL is a thin abstraction layer over PHP’s PDO (and native driver) extensions, giving applications one consistent API for connecting to and querying MySQL, PostgreSQL, SQLite, Oracle, SQL Server, MariaDB, IBM DB2, and more. Rather than writing raw, engine-specific SQL, developers use its fluent QueryBuilder to construct SELECT/INSERT/UPDATE/DELETE statements, and its Platforms layer translates DBAL’s neutral SQL into the correct dialect for whichever database is configured.
Beyond query execution, DBAL includes a Schema component for introspecting and diffing database structure (tables, columns, indexes, foreign keys) programmatically, which is what powers Doctrine ORM’s migrations and schema-sync tooling — though DBAL itself is fully usable standalone, without adopting the full ORM.
What You Get
- A fluent
QueryBuilderfor constructing SELECT/INSERT/UPDATE/DELETE queries programmatically - A
Platformsabstraction that translates neutral SQL into the correct dialect per database engine - A
Schemacomponent for introspecting and diffing tables, columns, indexes, and foreign keys - A
Typessystem mapping PHP types to database column types consistently across platforms - Connection management, transaction handling, and portability helpers (case normalization, etc.)
- Support for MySQL/MariaDB, PostgreSQL, SQLite, Oracle, SQL Server, and IBM DB2
Common Use Cases
- Writing database queries that need to run unchanged across multiple RDBMS engines
- Building or running Doctrine ORM’s schema migrations and diffing tooling
- Introspecting an existing database’s schema programmatically for tooling or codegen
- Using a query builder for raw SQL access without adopting a full ORM’s entity-mapping layer
Under The Hood
Architecture - Connection.php wraps a Driver (in src/Driver/) that adapts PDO or native extensions per engine, Query.php/Query/QueryBuilder builds abstract syntax that the matching Platforms/*Platform.php class renders into engine-specific SQL, while Schema/ provides Table/Column/SchemaDiff classes that introspect live databases via platform-specific SchemaManager implementations. Tech Stack - Modern PHP (8.1+) with strict static analysis enforced via PHPStan (phpstan-baseline.neon, phpstan.neon.dist) and coding-standard checks via PHP_CodeSniffer, packaged and versioned through Composer, part of the broader Doctrine project ecosystem. Code Quality - A 20+ directory tests/ suite covering functional tests per platform and unit tests per component, combined with a strict static-analysis baseline and a documented UPGRADE.md for every major version, reflects mature, disciplined engineering across 649 contributors. API Design - The QueryBuilder’s fluent, chainable methods (->select()->from()->where()) closely mirror SQL itself, keeping the learning curve low for anyone who already knows SQL, while the Schema/Types layers require more study to use well for advanced introspection or custom type mapping.
Used by 14 apps in this directory
Magic
AI Agents · Automation · Low Code Platforms
Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.
Mautic
Automation · Ecommerce · Marketing
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
OpnForm
Forms Surveys · Marketing
Build unlimited, embeddable forms with no code — powered by AI, logic rules, and real-time analytics
Shlink
Developer Tools · Marketing
Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.