PHPackages                             pine3ree/p3-pdo - 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. pine3ree/p3-pdo

Abandoned → [pine3ree/pine3ree-pdo](/?search=pine3ree%2Fpine3ree-pdo)Library[Database &amp; ORM](/categories/database)

pine3ree/p3-pdo
===============

A tiny PDO wrapper for lazy instantiation and query profiling

3.0.1(2y ago)240BSD-3-ClausePHPPHP ~8.0.0 || ~8.1.0 || ~8.2.0

Since Apr 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/pine3ree/pine3ree-pdo)[ Packagist](https://packagist.org/packages/pine3ree/p3-pdo)[ Docs](https://github.com/pine3ree/pine3ree-pdo)[ RSS](/packages/pine3ree-p3-pdo/feed)WikiDiscussions 3.0.x Synced today

READMEChangelog (10)Dependencies (4)Versions (28)Used By (0)

pine3ree-PDO
============

[](#pine3ree-pdo)

[![Continuous Integration](https://github.com/pine3ree/pine3ree-pdo/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0.x)](https://github.com/pine3ree/pine3ree-pdo/actions/workflows/continuous-integration.yml)

*A lazy-loading PDO drop-in replacement!*

pine3ree-PDO extends PHP ext-PDO in order to provide on demand connection, connection expiration with auto-reconnect and query logging/profiling.

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

[](#installation)

This version (`3.0.x`) of the library requires `php ~8.0 || ~8.1.0 || ~8.2.0`.

For php-7.4 support please use version `2.0.x`.

You can install it library using Composer (with "minimum-stability": "dev"):

```
$ composer require pine3ree/pine3ree-pdo
```

Documentation
-------------

[](#documentation)

Check the [php PDO book](https://www.php.net/manual/en/book.pdo.php) for standard ext PDO methods.

Continue reading below for additional methods.

### How to use the lazy pdo instance

[](#how-to-use-the-lazy-pdo-instance)

Just instantiate the provided lazy class as you would with the standard ext-pdo PDO class. A wrapped standard PDO instance will be created on demand when really needed.

```
$pdo = new pine3ree\PDO(
    $dsn = 'sqlite:my-db.sqlite3',
    $username = '',
    $password = '',
    $options = []
);
```

By default `pine3ree\PDO` and its descendant `pine3ree\PDO\Reconnecting\PDO` establish a database connection on demand.

The methods that trigger the connection are:

- `pine3ree\PDO::beginTransaction()`;
- `pine3ree\PDO::exec(...)`;
- `pine3ree\PDO::prepare(...)`;
- `pine3ree\PDO::query(...)`;
- `pine3ree\PDO::quote(...)`;
- `pine3ree\PDO::execute(...)`;

### How to enable query-profiling

[](#how-to-enable-query-profiling)

Query logging/profiling can be achieved via the provided profiling class and passing another pdo instance (either a standard ext-pdo instance or an instance of a class extending it (such as the lazy-pdo in this package) in the constructor:

```
$pdo = new pine3ree\PDO\Profiling\PDO(new \PDO(
    $dsn = 'sqlite:my-db.sqlite3',
    $username = '',
    $password = '',
    $options = []
));
```

You can retrieve the recorded information by calling the `pine3ree\PDO\Profiling\PDO::getLog()` method.

### How to use the auto-reconnecting/connection-expiration instance

[](#how-to-use-the-auto-reconnectingconnection-expiration-instance)

Use the provided reconnecting-pdo class with an extra `$ttl` constructor argument:

```
$pdo = new pine3ree\PDO\Reconnecting\PDO(
    $dsn = 'sqlite:my-db.sqlite3',
    $username = '',
    $password = '',
    $options = [],
    $ttl = 6 // drops the current connection after 6 seconds and establish a new one on demand
);
```

### Additional methods

[](#additional-methods)

#### pine3ree\\PDO::execute(): \\PDOStatement|false

[](#pine3reepdoexecute-pdostatementfalse)

```
pine3ree\PDO::execute(string $statement, array $input_parameters = [], array $driver_options = [])

```

combines `\PDO::prepare()` and `\PDOStatement::execute()` into one method call, returning `false` if either the statement preparation or execution fails.

This method is inherited by `pine3ree\PDO\Reconnecting\PDO`.

#### pine3ree\\PDO::isConnected(): bool

[](#pine3reepdoisconnected-bool)

checks if we have an established database connection.

This method is inherited by `pine3ree\PDO\Reconnecting\PDO` and also implemented in `pine3ree\PDO\Profiling\PDO`.

#### pine3ree\\PDO\\Profiling\\PDO::getLog(): array

[](#pine3reepdoprofilingpdogetlog-array)

returns recorded profiling information about all the executed statements in the following format:

```
[
    // every runned query including re-runs
    'statements' => [
        0 => [...],
        1 => [...],
        //....
        n => [
            'sql'    => "SELECT * FROM `user` WHERE `id` = :id",
            'iter'   => 2, // the iteration index for this sql expression
            'time'   => 0.000254..., // in seconds.microseconds
            'params' => [':id' => 123]
        ],
    ],
    // queries indexed by sql expression
    'reruns' => [
        'md5(sql1)' => [...],
        //...,
        'md5(sqln)' => [
            'sql'    => "SELECT * FROM `users` WHERE `status` = 1",
            'iter'   => 5, // the number of iterations for this sql expression
            'time'   => 0.001473..., // total time for all re-runs
        ],
    ],
    'time'  => 23.5678, // total query time
    'count' => 15, // total query count
];
```

#### pine3ree\\PDO\\Reconnecting\\PDO::getConnectionCount(): int

[](#pine3reepdoreconnectingpdogetconnectioncount-int)

returns the number of database connections performed so far

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~47 days

Recently: every ~2 days

Total

28

Last Release

939d ago

Major Versions

0.6.0 → 1.0.02021-02-24

1.1.1 → 2.0.02023-09-21

1.2.x-dev → 3.0.02023-10-05

2.0.4 → 3.0.12023-10-05

2.0.5 → 3.0.x-dev2023-10-14

PHP version history (3 changes)0.4.0PHP ^7.0

2.0.0PHP ^7.4 || ~8.0.0

3.0.0PHP ~8.0.0 || ~8.1.0 || ~8.2.0

### Community

Maintainers

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

---

Top Contributors

[![pine3ree](https://avatars.githubusercontent.com/u/3229979?v=4)](https://github.com/pine3ree "pine3ree (53 commits)")

---

Tags

databasepdopine3reelazy-pdo

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pine3ree-p3-pdo/health.svg)

```
[![Health](https://phpackages.com/badges/pine3ree-p3-pdo/health.svg)](https://phpackages.com/packages/pine3ree-p3-pdo)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5656.7M231](/packages/nette-database)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5013.8M120](/packages/dibi-dibi)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)

PHPackages © 2026

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