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,705 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
94 /100 Excellent
Development Activity 100
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

PHP
82%
Other

Akaunting

Invoicing Finance

10,149

Open-source online accounting for small businesses and freelancers — invoices, expenses, and reporting without monthly fees or vendor lock-in.

View details
98
Repo Health
73
Technical
63
Dependency
Built with
PHP 82%
Blade 13%
Updated 1 weeks ago
PHP
81%
Apache 2.0

Coolify

Devops · Hosting Control Panel

62,328

Open-source self-hosted PaaS — deploy apps, databases and 280+ services on your own servers with no vendor lock-in

View details
92
Repo Health
86
Technical
70
Dependency
Built with
PHP 81%
Blade 16%
Updated 1 weeks ago
PHP
48%
AGPL 3.0

Crater

Invoicing Finance

8,349

Open source invoicing and billing platform for freelancers and small businesses — create estimates, track expenses, accept Stripe payments, and run recurring invoices from your own server.

View details
54
Repo Health
68
Technical
68
Dependency
Built with
PHP 48%
Vue 40%
Updated 2 years ago
PHP
66%
AGPL 3.0

EspoCRM

CRM · Ecommerce · Marketing

3,417

Open-source CRM platform with metadata-driven customization, field-level permissions, and a full REST API — deploy on your own infrastructure.

View details
96
Repo Health
72
Technical
63
Dependency
Built with
PHP 66%
JavaScript 23%
Updated 1 weeks ago
PHP
91%
AGPL 3.0

FreeScout

Customer Support

4,565

Run your own help desk and shared inbox — a fully self-hosted, open-source alternative to Zendesk and Help Scout with no per-agent fees.

View details
93
Repo Health
55
Technical
63
Dependency
Built with
PHP 91%
Updated 1 weeks ago
PHP
58%
Other

Hi.Events

Ecommerce · Scheduling

4,037

Self-hosted event ticketing platform that keeps your attendee data, brand, and revenue completely under your control.

View details
88
Repo Health
84
Technical
66
Dependency
Built with
PHP 58%
TypeScript 36%
Updated 2 weeks ago
PHP
63%
AGPL 3.0

Hyvor Relay

AI Development · Devops · Monitoring

908

Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.

View details
68
Repo Health
79
Technical
70
Dependency
Built with
PHP 63%
Svelte 23%
Go 11%
Updated 2 weeks ago
PHP
48%
AGPL 3.0

Leantime

Collaboration · Productivity · Project Management

11,672

Project management built for ADHD, autism, and dyslexia — simple as Trello, powerful as Jira

View details
90
Repo Health
68
Technical
65
Dependency
Built with
PHP 48%
CSS 20%
Blade 17%
Updated 2 weeks ago
PHP
65%
AGPL 3.0

LinkStack

Marketing

3,888

Self-hosted, privacy-focused Linktree alternative with themes, analytics, and a drag-and-drop admin panel.

View details
66
Repo Health
56
Technical
68
Dependency
Built with
PHP 65%
Blade 35%
Updated 2 months 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