PHPackages                             vermaysha/pgbouncer-laravel-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. vermaysha/pgbouncer-laravel-extension

ActiveLibrary[Database &amp; ORM](/categories/database)

vermaysha/pgbouncer-laravel-extension
=====================================

A Laravel extension to support PgBouncer with emulated prepared statements for PostgreSQL connections.

0.0.5-beta.3(10mo ago)53.9k↓20.7%MITPHPPHP ^8.1CI passing

Since Jul 1Pushed 10mo agoCompare

[ Source](https://github.com/vermaysha/pgbouncer-laravel-extension)[ Packagist](https://packagist.org/packages/vermaysha/pgbouncer-laravel-extension)[ RSS](/packages/vermaysha-pgbouncer-laravel-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (8)Used By (0)

Laravel PgBouncer Emulated Prepare Extension
============================================

[](#laravel-pgbouncer-emulated-prepare-extension)

A simple Laravel extension to enable the use of PgBouncer in transaction pooling mode by correctly handling value bindings when `PDO::ATTR_EMULATE_PREPARES` is enabled for a PostgreSQL connection.

The Problem
-----------

[](#the-problem)

When using PgBouncer in transaction pooling mode (`pool_mode = transaction`), it does not support prepared statements. The standard solution for Laravel is to disable them by setting `PDO::ATTR_EMULATE_PREPARES` to `true` in your `config/database.php` file.

However, when this option is enabled, Laravel's default `PostgresConnection` does not correctly handle boolean values, casting them to `1` or `0` instead of the required `'true'` or `'false'` strings, which leads to SQL errors.

This package transparently solves this issue by providing a custom connection class that correctly handles data type conversions for emulated prepared statements.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require vermaysha/pgbouncer-laravel-extension
```

The package will automatically register its service provider.

Usage
-----

[](#usage)

After installation, the only step is to configure your PostgreSQL database connection to use emulated prepared statements.

In your `config/database.php` file, find your `pgsql` connection and add the `options` key with `PDO::ATTR_EMULATE_PREPARES` set to `true`.

```
// config/database.php

'connections' => [

    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'laravel'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',

        // Add this option
        'options' => [
            PDO::ATTR_EMULATE_PREPARES => true,
        ],
    ],
],
```

That's it! The service provider will detect this setting and automatically use the custom connection class for any `pgsql` connection that has emulated prepares enabled.

Testing
-------

[](#testing)

This package is fully tested. To run the tests locally, first set up your environment:

Ensure you have Docker installed and running.

Start the test database using Docker Compose:

```
docker-compose up -d
```

Run the test suite using Composer:

```
composer test
```

Alternatively, you can run phpunit directly:

```
vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.

Credits
-------

[](#credits)

Author: [Ashary Vermaysha](https://github.com/vermaysha)

Contributor: [Google Gemini](https://gemini.google.com)

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance54

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 61.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

322d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e558f4a7637a3d075d40d9eff82894bd5916e589d1bfd9630aae91f3a0a1524c?d=identicon)[vermaysha](/maintainers/vermaysha)

---

Top Contributors

[![vermaysha](https://avatars.githubusercontent.com/u/34608589?v=4)](https://github.com/vermaysha "vermaysha (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (1 commits)")

---

Tags

databaselaravelpgbouncerpostgresqlpsqllaraveldatabasepostgresqlpgsqlpgbouncer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vermaysha-pgbouncer-laravel-extension/health.svg)

```
[![Health](https://phpackages.com/badges/vermaysha-pgbouncer-laravel-extension/health.svg)](https://phpackages.com/packages/vermaysha-pgbouncer-laravel-extension)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[vcian/laravel-db-auditor

Database DB Auditor provide leverage to audit your MySql,sqlite, PostgreSQL database standards and also provide options to add constraints in table.

28535.1k1](/packages/vcian-laravel-db-auditor)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[aimeos/laravel-nestedset

Nested Set Model for Laravel

292.0k2](/packages/aimeos-laravel-nestedset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
