Skip to content

New PSR for providing PDO connections (PdoProviderInterface)#1348

Draft
maximegosselin wants to merge 1 commit intophp-fig:masterfrom
maximegosselin:master
Draft

New PSR for providing PDO connections (PdoProviderInterface)#1348
maximegosselin wants to merge 1 commit intophp-fig:masterfrom
maximegosselin:master

Conversation

@maximegosselin
Copy link
Copy Markdown

There is no standard contract for passing a PDO connection between libraries, and passing \PDO directly surrenders control over the connection lifecycle.

Goal

Provide a minimal interface that decouples PDO connection consumption from connection lifecycle management, and enables interoperability between libraries that need a connection and those that manage one.

Background

https://maximegosselin.com/posts/proposing-a-psr-for-pdo-providers/

@maximegosselin maximegosselin requested a review from a team as a code owner March 11, 2026 02:43
@Jean85
Copy link
Copy Markdown
Member

Jean85 commented Mar 11, 2026

Hi @maximegosselin, thank you for drafting your proposal. To make this go further, I suggest you to look at our PSR workflow, which this proposal should follow.

I would suggest to reach out to whomever should adopt this interface (i.e. Doctrine) to have them onboard, which would raise the probability of this being accepted.

I'll switch this to draft for now.

@Jean85 Jean85 marked this pull request as draft March 11, 2026 08:22
@Jean85 Jean85 added the New PSR label Mar 11, 2026
@samdark
Copy link
Copy Markdown
Member

samdark commented Mar 11, 2026

Does it have to be bound to PDO?

@maximegosselin
Copy link
Copy Markdown
Author

maximegosselin commented Mar 11, 2026

Does it have to be bound to PDO?

Could you please elaborate? I'm not sure what "bound to PDO" means in this context. Are you suggesting the interface should return a more generic type, or something else entirely?

@KorvinSzanto
Copy link
Copy Markdown
Contributor

I'm not really sure I see the benefit here as stated. In general, a library that consumes a PDO connection can already be interoperable by simply accepting the connection itself via DI.

Can you be more specific about why hinting on something like PdoProviderInterface rather than just the connection itself is beneficial? Is it just to reconnect if the connection has timed out?

@maximegosselin
Copy link
Copy Markdown
Author

maximegosselin commented Mar 12, 2026

To provide supporting evidence for this proposal, I've put together a research repository that demonstrates how 10 popular PHP database libraries handle PDO connections in practice:

https://github.com/maximegosselin/pdo-provider-research

It covers three scenarios for each library:

  1. creating a connection from configuration
  2. accepting an existing PDO object
  3. exposing the internal PDO instance.

The consistent pattern across library types supports the case for a standard PdoProviderInterface.

Libraries covered:

  • atlas/orm
  • aura/sql
  • cakephp/database
  • clancats/hydrahon
  • doctrine/dbal
  • envms/fluentpdo
  • illuminate/database
  • nette/database
  • paragonie/easydb
  • php-db/phpdb

@maximegosselin
Copy link
Copy Markdown
Author

I'm not really sure I see the benefit here as stated. In general, a library that consumes a PDO connection can already be interoperable by simply accepting the connection itself via DI.

Can you be more specific about why hinting on something like PdoProviderInterface rather than just the connection itself is beneficial? Is it just to reconnect if the connection has timed out?

@KorvinSzanto That's a fair point. Accepting \PDO directly via DI works but it ties the consumer to an already-open connection and gives it no control over the lifecycle. With PdoProviderInterface, the provider decides when and how to open the connection.

A concrete example: Doctrine DBAL has lazy connection support built in. With a standard PdoProviderInterface, you could pass a Doctrine DBAL provider directly into FluentPDO (instead of a \PDO), and FluentPDO would get a connection only when it actually runs a query. Today, there is no standard way to do that. Each library manages its own connection and there is no common contract to bridge them.

@Crell
Copy link
Copy Markdown
Contributor

Crell commented Mar 12, 2026

@maximegosselin Please keep the discussion on the list, not in the PR. That way there's only one place folks need to follow.

@maximegosselin
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants