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

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

tebe/pdo
========

Provides an extension to the native PDO along with additional functionality.

v1.0.0(4mo ago)6222[1 PRs](https://github.com/tbreuss/pdo/pulls)MITPHPPHP &gt;=8.2CI passing

Since Feb 7Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tbreuss/pdo)[ Packagist](https://packagist.org/packages/tebe/pdo)[ Docs](https://github.com/tebe/pdo)[ RSS](/packages/tebe-pdo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (8)Used By (0)

[![PHP Version Require](https://camo.githubusercontent.com/d30ac8ca24a4653b0e60211bf26cf4d5f935d3a3607d924812e51048ab589b85/687474703a2f2f706f7365722e707567782e6f72672f746562652f70646f2f726571756972652f706870)](https://packagist.org/packages/tebe/pdo)[![Version](https://camo.githubusercontent.com/26fbb7c88595b7cbd4be2ff47e034f5779e76cfd610bef3002a335276543da65/687474703a2f2f706f7365722e707567782e6f72672f746562652f70646f2f76657273696f6e)](https://packagist.org/packages/tebe/pdo)[![Testing tebe\pdo](https://github.com/tbreuss/pdo/actions/workflows/tests.yml/badge.svg)](https://github.com/tbreuss/pdo/actions/workflows/tests.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

tebe\\pdo
=========

[](#tebepdo)

Provides an extension to the native PDO along with additional functionality.

`tebe\pdo` is an extension of the native PDO in the style of a thin wrapper. All constants, properties and methods of the underlying PDO classes are therefore available. Code already using or typehinted to the native PDO can use `tebe\pdo` with minimal changes for the most part.

Added or changed functionality in `tebe\pdo` over the native PDO includes:

- Exceptions by default. `tebe\pdo` starts in the ERRMODE\_EXCEPTION mode for error reporting instead of the ERRMODE\_SILENT mode.
- New `PDO::run()` method. This is for convenience to prepare and execute an SQL statement in one step.
- Bind array of values to placeholder in `PDO::run()` method. Placeholders that represent array values will be replaced with comma-separated quoted values. This means you can bind an array of values to a placeholder used with an IN (...) condition.
- Array quoting. The `PDO::quote()` method will accept an array as input, and return a string of comma-separated quoted values.
- New `PDOStatement::fetch*()` methods. The new methods provide for commonly-used fetch actions.
- New `PDOStatement::fetchAll*()` methods. The new methods provide for commonly-used fetch all actions.

Examples
--------

[](#examples)

Create a PDO instance representing a connection to a database.

```
use tebe\pdo\PDO;
$db = new PDO('sqlite:database.sqlite');
```

Execute an SQL statement without placeholders and return the number of affected rows.

```
$sql = "INSERT INTO fruits VALUES
(1, 'Banana', 'yellow', 250),
(2, 'Apple', 'red', 150),
(3, 'Pear', 'green', 150),
(4, 'Orange', 'orange', 300),
(5, 'Lime', 'green', 333),
(6, 'Lemon', 'yellow', 25),
(7, 'Peach', 'orange', 100),
(8, 'Cherry', 'red', 200)";
print $db->exec($sql);
// outputs 8
```

Prepare and execute an SQL statement without placeholders, and fetch all rows from the result set.

```
$sql = "SELECT name, color FROM fruits WHERE color = 'green' ORDER BY name";
print json_encode($db->query($sql)->fetchAll());
// outputs [{"name":"Lime","color":"green"},{"name":"Pear","color":"green"}]
```

Prepare a statement with placeholders for execution, return a statement object, and fetch all columns from the result set.

```
$sql = "SELECT name FROM fruits WHERE color = ? ORDER BY name";
print json_encode($db->prepare($sql)->execute(['red'])->fetchAllColumn());
// outputs ["Apple","Cherry"]
```

Run a query with placeholders, return the resulting PDOStatement, and fetch key value array (pairs) from the result set.

```
$sql = "SELECT name, calories FROM fruits WHERE color = ? ORDER BY name";
print json_encode($db->run($sql, ['red'])->fetchAllPair());
// outputs {"Banana":250,"Lemon":25}
```

Run a query with an IN clause and placeholders, return the resulting PDOStatement, and fetch all rows grouped by color from the result set.

```
$sql = "SELECT color, name FROM fruits WHERE color IN (?) ORDER BY name";
print json_encode($db->run($sql, [['green', 'red']])->fetchAllGroup());
// outputs {"red":[{"name":"Apple"},{"name":"Cherry"}],"green":[{"name":"Lime"},{"name":"Pear"}]}
```

Quote an array for use in a query.

```
print $db->quote(['red', 'green', 'yellow']);
// outputs 'red', 'green', 'yellow'
```

Installation and Autoloading
----------------------------

[](#installation-and-autoloading)

This package is installable and PSR-4 autoloadable via Composer as `tebe/pdo`.

Alternatively, download a release, or clone this repository, then include the classes manually:

```
include '{path/to/tebe/pdo}/src/PDO.php';
include '{path/to/tebe/pdo}/src/PDOStatement.php';
include '{path/to/tebe/pdo}/src/PDOParser.php';
```

Dependencies
------------

[](#dependencies)

This package requires PHP 8.2 or later; it has been tested on latest Linux, macOS and Windows on PHP 8.2-8.6. We recommend using the latest available version of PHP as a matter of principle. `tebe\pdo` doesn't depend on other external packages.

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

[](#documentation)

### tebe\\pdo\\PDO

[](#tebepdopdo)

The class `tebe\pdo\PDO` is a wrapper for the native `PDO` class and implements all methods of this class.

The main differences are that some methods return `tebe\pdo\PDOStatement` instances and the `quote` method can also handle arrays.

In addition, the class contains a new method `run`, which executes a query with bound values and returns the resulting statement instance.

#### getWrappedPdo

[](#getwrappedpdo)

Returns the underlying PDO instance.

```
public PDO::getWrappedPdo(): \PDO
```

#### prepare

[](#prepare)

Prepares a statement for execution and returns a statement object.

This differs from `PDO::prepare` in that it will return a `tebe\pdo\PDOStatement` object.

```
public PDO::prepare(string $query, array $options = []): PDOStatement|false
```

See [php.net](https://php.net/pdo.prepare)

#### query

[](#query)

Prepares and executes an SQL statement without placeholders.

This differs from `PDO::query` in that it will return a `tebe\pdo\PDOStatement` object.

```
public PDO::query(string $query, mixed ...$fetchModeArgs): PDOStatement|false
```

See [php.net](https://php.net/pdo.query)

#### quote

[](#quote)

Quotes a string for use in a query.

This differs from `PDO::quote` in that it will convert an array into a string of comma-separated quoted values.

```
public PDO::quote(array|string|int|float|null $value, int $type = PDO::PARAM_STR): string|false
```

See [php.net](https://php.net/pdo.quote)

#### run

[](#run)

Runs a query with bound values and returns the resulting `tebe\pdo\PDOStatement`.

Array values will be processed by the parser instance and placeholders are replaced.

```
public PDO::run(string $sql, ?array $args = null): PDOStatement|false
```

---

The remaining `tebe\pdo\PDO` methods are simple wrapper methods of the underlying `PDO` class. For more information, see [php.net](https://php.net/pdo).

- [beginTransaction](https://php.net/pdo.beginTransaction)
- [commit](https://php.net/pdo.commit)
- [\_\_construct](https://php.net/pdo.__construct)
- [errorCode](https://php.net/pdo.errorCode)
- [errorInfo](https://php.net/pdo.errorInfo)
- [exec](https://php.net/pdo.exec)
- [getAttribute](https://php.net/pdo.getAttribute)
- [getAvailableDrivers](https://php.net/pdo.getAvailableDrivers)
- [inTransaction](https://php.net/pdo.inTransaction)
- [lastInsertId](https://php.net/pdo.lastInsertId)
- [rollBack](https://php.net/pdo.rollBack)
- [setAttribute](https://php.net/pdo.setAttribute)

### tebe\\pdo\\PDOStatement

[](#tebepdopdostatement)

The class `tebe\pdo\PDOStatement` is a wrapper for the native `PDOStatement` class and implements all methods of this class.

The main difference is that the `execute` method returns a statement instance. This was done to allow method chaining aka fluent interface.

Besides that it contains several new `fetch*()` and `fetchAll*()` methodes for commonly-used fetch actions.

#### \_\_construct

[](#__construct)

Creates a `tebe\pdo\PDOStatement` instance representing a query statement and wraps the original `PDOStatement`.

```
public PDOStatement::__construct(\PDOStatement $stmt)
```

#### execute

[](#execute)

Executes a prepared statement

This differs from `PDOStatement::execute` in that it will return a `tebe\pdo\PDOStatement` object.

```
public PDOStatement::execute(?array $params = null): PDOStatement|false
```

See [php.net](https://php.net/pdostatement.execute)

#### fetchAffected

[](#fetchaffected)

Fetches the number of affected rows from the result set.

```
public PDOStatement::fetchAffected(): int
```

#### fetchAssoc

[](#fetchassoc)

Fetches the next row from the result set as an associative array.

```
public PDOStatement::fetchAssoc(): array|false
```

#### fetchBoth

[](#fetchboth)

Fetches the next row from the result set as an associative and indexed array.

```
public PDOStatement::fetchBoth(): array|false
```

#### fetchInto

[](#fetchinto)

Fetches the next row from the result as the updated passed object, by mapping the columns to named properties of the object.

```
public PDOStatement::fetchInto(object $object): object|false
```

#### fetchNamed

[](#fetchnamed)

Fetches the next row from the result set as an associative array; If the result set contains multiple columns with the same name, an array of values per column name is returned.

```
public PDOStatement::fetchNamed(): array|false
```

#### fetchNumeric

[](#fetchnumeric)

Fetches the next row from the result set as an indexed array.

```
public PDOStatement::fetchNumeric(): array|false
```

#### fetchPair

[](#fetchpair)

Fetches the next row from the result set as a key-value pair.

```
public PDOStatement::fetchPair(): array|false
```

#### fetchAllAssoc

[](#fetchallassoc)

Fetches all rows from the result set as an array of associative arrays.

```
public PDOStatement::fetchAllAssoc(): array
```

#### fetchAllBoth

[](#fetchallboth)

Fetches all rows from the result set as an array of associative and indexed arrays.

```
public PDOStatement::fetchAllBoth(): array
```

#### fetchAllColumn

[](#fetchallcolumn)

Fetches all rows from the result set as an array of a single column.

```
public PDOStatement::fetchAllColumn(int $column = 0): array
```

#### fetchAllFunction

[](#fetchallfunction)

Fetches all rows from the result set as an array by calling a function for each row.

```
public PDOStatement::fetchAllFunction(callable $callable): array
```

#### fetchAllGroup

[](#fetchallgroup)

Fetches all rows from the result set as an array by grouping all rows by a single column.

```
public PDOStatement::fetchAllGroup(int $style = 0): array
```

#### fetchAllNamed

[](#fetchallnamed)

Fetches all rows from the result set as an array of associative arrays; If the result set contains multiple columns with the same name, an array of values per column name is returned.

```
public PDOStatement::fetchAllNamed(): array
```

#### fetchAllNumeric

[](#fetchallnumeric)

Fetches all rows from the result set as an array of indexed arrays.

```
public PDOStatement::fetchAllNumeric(): array
```

#### fetchAllObject

[](#fetchallobject)

Fetches all rows from the result set as an array of objects of the requested class, mapping the columns to named properties in the class.

```
public PDOStatement::fetchAllObject(string $class = 'stdClass', ?array $constructorArgs = null, int $style = 0): array
```

#### fetchAllPair

[](#fetchallpair)

Fetches all rows from the result set as an array of key-value pairs.

```
public PDOStatement::fetchAllPair(): array
```

#### fetchAllUnique

[](#fetchallunique)

Fetches all rows from the result set as an array of arrays, indexed by an unique field.

```
public PDOStatement::fetchAllUnique(int $style = 0): array
```

---

The remaining `tebe\pdo\PDOStatement` methods are simple wrapper methods of the underlying `PDOStatement` class. For more information, see [php.net](https://php.net/pdostatement).

- [bindColumn](https://php.net/pdostatement.bindcolumn)
- [bindParam](https://php.net/pdostatement.bindParam)
- [bindValue](https://php.net/pdostatement.bindValue)
- [closeCursor](https://php.net/pdostatement.closeCursor)
- [columnCount](https://php.net/pdostatement.columnCount)
- [debugDumpParams](https://php.net/pdostatement.debugDumpParams)
- [errorCode](https://php.net/pdostatement.errorCode)
- [errorInfo](https://php.net/pdostatement.errorInfo)
- [fetch](https://php.net/pdostatement.fetch)
- [fetchAll](https://php.net/pdostatement.fetchAll)
- [fetchColumn](https://php.net/pdostatement.fetchColumn)
- [fetchObject](https://php.net/pdostatement.fetchObject)
- [getAttribute](https://php.net/pdostatement.getAttribute)
- [getColumnMeta](https://php.net/pdostatement.getColumnMeta)
- [getIterator](https://php.net/pdostatement.getIterator)
- [nextRowset](https://php.net/pdostatement.nextRowset)
- [rowCount](https://php.net/pdostatement.rowCount)
- [setAttribute](https://php.net/pdostatement.setAttribute)
- [setFetchMode](https://php.net/pdostatement.setFetchMode)

### tebe\\pdo\\PDOParser

[](#tebepdopdoparser)

Class `tebe\pdo\PDOParser` offers parsing and rebuilding functions for all drivers.

#### \_\_construct

[](#__construct-1)

Creates a `tebe\pdo\PDOParser` instance.

```
public PDOParser::__construct(string $driver)
```

#### rebuild

[](#rebuild)

Rebuilds a statement with placeholders and bound values.

```
public PDOParser::rebuild(string $statement, array $values = []): array
```

Quality
-------

[](#quality)

[![Testing tebe\pdo](https://github.com/tbreuss/pdo/actions/workflows/tests.yml/badge.svg)](https://github.com/tbreuss/pdo/actions/workflows/tests.yml)

This project adheres to [Semantic Versioning](https://semver.org/).

To run the functional tests at the command line, issue `composer install` and then `composer test` at the package root. (This requires [Composer](https://getcomposer.org/) to be available as `composer`.)

This package attempts to comply with [PSR-1](https://www.php-fig.org/psr/psr-1/), [PSR-4](https://www.php-fig.org/psr/psr-4/), and [PSR-12](https://www.php-fig.org/psr/psr-12/). If you notice compliance oversights, please send a patch via pull request.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance75

Regular maintenance activity

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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 ~139 days

Recently: every ~173 days

Total

6

Last Release

134d ago

Major Versions

v0.5.0 → v1.0.02026-01-04

PHP version history (2 changes)v0.1.0PHP &gt;=8.1

v1.0.0PHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![tbreuss](https://avatars.githubusercontent.com/u/1334161?v=4)](https://github.com/tbreuss "tbreuss (79 commits)")

---

Tags

databasepdopdo-instancepdo-phppdo-wrapperphpphp-pdomysqlsqlitepostgresqlpostgrespdopgsqlsqlserversqlsrvsql serverpdo-wrapper

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/tebe-pdo/health.svg)](https://phpackages.com/packages/tebe-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)[aura/sql

A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.

5632.5M43](/packages/aura-sql)[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)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41234.1k4](/packages/aura-sqlschema)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41249.0k7](/packages/atlas-query)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)

PHPackages © 2026

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