Download the PHP package t1nkl/postgres-pgbouncer-extension without Composer
On this page you can find all versions of the php package t1nkl/postgres-pgbouncer-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download t1nkl/postgres-pgbouncer-extension
More information about t1nkl/postgres-pgbouncer-extension
Files in t1nkl/postgres-pgbouncer-extension
Package postgres-pgbouncer-extension
Short Description Laravel PostgreSQL pgbouncer extension fix for PDO::ATTR_EMULATE_PREPARES option
License MIT
Informations about the package postgres-pgbouncer-extension
Laravel PostgreSQL + PgBouncer extension (fix for PDO::ATTR_EMULATE_PREPARES)
A tiny Laravel package that makes working with PostgreSQL through PgBouncer safe and predictable when PDO::ATTR_EMULATE_PREPARES is enabled.
Why you might need it:
- PgBouncer in transaction/session pooling mode does not support server‑side prepared statements.
- The common workaround is to enable PDO emulated prepares (
PDO::ATTR_EMULATE_PREPARES => true). - With emulation enabled, default binding behavior in Laravel/PDO can cause booleans and some types to be sent in ways PgBouncer/PostgreSQL may not expect.
This package provides a custom PostgresConnection that:
- Formats
DateTimeInterfacevalues using your connection grammar date format. - Converts PHP booleans to the PostgreSQL-native textual values
'true'and'false'during binding. - Binds values using explicit PDO parameter types: integers as
PDO::PARAM_INT, resources asPDO::PARAM_LOB, and everything else asPDO::PARAM_STRfor consistency with emulated prepares.
The package is automatically discovered by Laravel and is only activated for the pgsql connection when PDO::ATTR_EMULATE_PREPARES is present and enabled in your connection options.
Requirements
- PHP: ^8.0
- Laravel Framework: ^10.0 | ^11.0 | ^12.0 | ^13.0
- PostgreSQL + PgBouncer (transaction or session pooling scenarios)
Installation
Laravel package auto-discovery will register the service provider; no manual configuration is needed beyond the database option below.
Configuration
Enable emulated prepares on your PostgreSQL connection. You can declare it either as an associative map or as a numeric flag — this package supports both styles.
config/database.php
Make sure your default connection is pgsql or that you add the options to the specific PostgreSQL connection you actually use.
If you modify configuration, remember to clear caches:
How it works
- The service provider hooks into Laravel’s connection resolver for
pgsqlonly whenPDO::ATTR_EMULATE_PREPARESis detected in the connectionoptions. - It swaps the default
Illuminate\Database\PostgresConnectionwithPostgresPgbouncerExtension\Database\PostgresConnection. - The custom connection overrides:
prepareBindings: convertsDateTimeInterfaceto the grammar date format and casts booleans to'true'/'false'strings.bindValues: binds integers asPDO::PARAM_INT, resources asPDO::PARAM_LOB, and all other values asPDO::PARAM_STRto keep behavior stable with emulated prepares.
Usage
There is nothing special to do. Once installed and the option is enabled, all queries through the pgsql connection will use the safer binding strategy.
Example: boolean filters are sent as 'true'/'false' which PostgreSQL parses natively.
Troubleshooting
- The behavior does not change:
- Ensure
PDO::ATTR_EMULATE_PREPARESis present in youroptionsand set totrue(or listed numerically). - Confirm your app uses the
pgsqlconnection you configured (config('database.default')). - Clear config/cache (
php artisan config:clear && php artisan cache:clear). - Make sure the package is installed and not excluded from auto-discovery.
- Ensure
- Still seeing unexpected parameter types?
- Double-check any custom connection/resolver code that might override this package.
- Try a minimal repro calling the query builder and logging SQL + bindings.
Testing locally
This repository includes a test suite. To run it:
Related work
Original gist/package inspiration: https://github.com/t1nkl/Laravel-PostgreSQL-pgbouncer-Fix
License
MIT License. See LICENSE for details.