Doctrine DBAL

A PHP database abstraction layer with a fluent query builder and schema introspection across major RDBMS engines

Library
Composer
v4.5.0
9,700 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
93 /100 Excellent
Development Activity 96
Maintenance 96
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 85
Code Quality 88
Innovation 60
Learning Curve 65

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 QueryBuilder for constructing SELECT/INSERT/UPDATE/DELETE queries programmatically
  • A Platforms abstraction that translates neutral SQL into the correct dialect per database engine
  • A Schema component for introspecting and diffing tables, columns, indexes, and foreign keys
  • A Types system 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

TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

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.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
PHP
81%
Other

Mautic

Automation · Ecommerce · Marketing

10,830

The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.

View details
98
Repo Health
76
Technical
63
Dependency
Built with
PHP 81%
Updated 6 days ago
PHP
62%
Other

OpnForm

Forms Surveys · Marketing

3,865

Build unlimited, embeddable forms with no code — powered by AI, logic rules, and real-time analytics

View details
91
Repo Health
75
Technical
65
Dependency
Built with
PHP 62%
Vue 28%
Updated 6 days ago
PHP
99%
MIT

Shlink

Developer Tools · Marketing

5,366

Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.

View details
84
Repo Health
83
Technical
73
Dependency
Built with
PHP 99%
Updated 1 weeks ago
PHP
84%
MIT

wallabag

Bookmarks Archiving

13,023

Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.

View details
93
Repo Health
81
Technical
60
Dependency
Built with
PHP 84%
Twig 13%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers