PHPackages                             xsuchy09/e\_pdostatement - 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. xsuchy09/e\_pdostatement

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

xsuchy09/e\_pdostatement
========================

Drop in replacement for default PDOStatement class allowing devs to view an interpolated version of a parameterized query

3.0.0(6y ago)124Apache-2.0PHPPHP &gt;=7.2.0

Since Feb 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xsuchy09/E_PDOStatement)[ Packagist](https://packagist.org/packages/xsuchy09/e_pdostatement)[ Docs](https://github.com/xsuchy09/E_PDOStatement)[ RSS](/packages/xsuchy09-e-pdostatement/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (15)Used By (0)

E\_PDOStatement
===============

[](#e_pdostatement)

Extension to the default PHP PDOStatement class providing the ability to generate a version of a parameterized query with the parameters injected into the query string.

The result is generally suitable for logging activities, debugging and performance analysis.

View the [changelog](CHANGELOG.md)

Usage
-----

[](#usage)

PHP's PDO are a much improved way for handling database communications, but not being able to view a complete version of the query to be executed on the server after statement parameters have been interpolated can be frustrating.

A common method for obtaining the interpolated query involves usage of outside functions or extending the native `PDOStatement` object and adding a new method to accomplish this.

The E\_PDOStatement (**E**nhanced PDOStatement) project was designed as a solution to this that doesn't require workflow modifications to generate the resultant query string. The generated query string is accessible on the new `EPDOStatement` object as a new `fullQuery` property :

```
$content    = $_POST['content'];
$title      = $_POST['title'];
$date       = date('Y-m-d');

$query      = 'INSERT INTO posts SET content = :content, title = :title, date = :date';
$stmt       = $pdo->prepare($query);

$stmt->bindParam(':content', $content, PDO::PARAM_STR);
$stmt->bindParam(':title'  , $title  , PDO::PARAM_STR);
$stmt->bindParam(':date'   , $date   , PDO::PARAM_STR);

$stmt->execute();

echo $stmt->fullQuery;
```

The result of this will be (on a MySQL database):

```
INSERT INTO posts SET content = 'There are several reasons you shouldn\'t do that, including [...]', title = 'Why You Shouldn\'t Do That', date = '2016-05-13'
```

When correctly configured, the interpolated values are escaped appropriately for the database driver, allowing the generated string to be suitable for e.g. log files, backups, etc.

E\_PDOStatement supports pre-execution binding to both named and ? style parameter markers:

```
$query      = 'INSERT INTO posts SET content = ?, title = ?, date = ?';
...

$stmt->bindParam(1, $content, PDO::PARAM_STR);
$stmt->bindParam(2, $title  , PDO::PARAM_STR);
$stmt->bindParam(3, $date   , PDO::PARAM_STR);
```

as well as un-named parameters provided as input arguments to the `$stmt->execute()` method:

```
$query      = 'INSERT INTO posts SET content = ?, title = ?, date = ?';

...

$params     = [$content, $title, $date];

$stmt->execute($params);
```

Named $key =&gt; $value pairs can also be provided as input arguments to the `$stmt->execute()` method:

```
$query      = 'INSERT INTO posts SET content = :content, title = :title, date = :date';

...

$params     = array(
    ':content' => $content,
    ':title'   => $title,
    ':date'    => $date,
);

$stmt->execute($params);
```

You can also generate the full query string without executing the query:

```
$content    = $_POST['content'];
$title      = $_POST['title'];
$date       = date('Y-m-d');

$query      = 'INSERT INTO posts SET content = :content, title = :title, date = :date';
$stmt       = $pdo->prepare($query);

$stmt->bindParam(':content', $content, PDO::PARAM_STR);
$stmt->bindParam(':title'  , $title  , PDO::PARAM_STR);
$stmt->bindParam(':date'   , $date   , PDO::PARAM_STR);

$fullQuery  = $stmt->interpolateQuery();
```

or

```
$content    = $_POST['content'];
$title      = $_POST['title'];
$date       = date('Y-m-d');

$query      = 'INSERT INTO posts SET content = ?, title = ?, date = ?';
$stmt       = $pdo->prepare($query);

$params     = [
    $content,
    $title,
    $date
];

$fullQuery  = $stmt->interpolateQuery($params);
```

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

[](#installation)

Preferred method: install using composer:

### PHP 7.2+

[](#php-72)

```
"require" : {
	"xsuchy09/e_pdostatement" : "3.*"
}
```

### PHP &lt; 7.2

[](#php--72)

```
"require" : {
	"xsuchy09/e_pdostatement" : "2.*"
}
```

Alternatively, you can simply download the project, put it into a suitable location in your application directory and include into your project as needed.

Configuration
-------------

[](#configuration)

The EPDOStatement class extends the native \\PDOStatement object, so the PDO object must be configured to use the extended definition:

```
require_once 'path/to/vendor/autoload.php';

/**
 * -- OR --
 *
 * require_once 'EPDOStatement.php';
 */

$dsn        = 'mysql:host=localhost;dbname=myDatabase';
$pdo        = new PDO($dsn, $dbUsername, $dbPassword);

$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['EPDOStatement\EPDOStatement', [$pdo]]);
//$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('EPDOStatement\EPDOStatement', array($pdo))); // older php versions
```

That's all there is to it.

Ideally, your project would have a PDO abstraction/wrapper class allowing you to implement this modification in only one place. If you don't have this luxury, success was shown with extending the \\PDO class to set the ATTR\_STATEMENT\_CLASS attribute in the constructor of the PDO.

Get in Touch
------------

[](#get-in-touch)

There are a lot of forum posts related to or requesting this type of functionality, so hopefully someone somewhere will find it helpful. If it helps you, comments are of course appreciated.

Bugs, new feature requests and pull requests are of course welcome as well. This was created to help our pro team solve an issue, so it was designed around our specific work flow. If it doesn't work for you though, let me know and I'll be happy to explore if I can help you out.

#### E\_mysqli

[](#e_mysqli)

E\_PDOStatement now has a sister project aimed at providing the same functionality for php devs using the `mysqli` extension:

[E\_mysqli](https://github.com/noahheck/E_mysqli)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 78.8% 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 ~150 days

Recently: every ~299 days

Total

12

Last Release

2452d ago

Major Versions

v1.2.1 → v2.0.02015-02-07

2.2.2 → 3.0.02019-08-21

PHP version history (2 changes)v1.2.1PHP &gt;=5.1.0

3.0.0PHP &gt;=7.2.0

### Community

Maintainers

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

---

Top Contributors

[![noahheck](https://avatars.githubusercontent.com/u/4154306?v=4)](https://github.com/noahheck "noahheck (41 commits)")[![xsuchy09](https://avatars.githubusercontent.com/u/1107359?v=4)](https://github.com/xsuchy09 "xsuchy09 (9 commits)")[![colshrapnel](https://avatars.githubusercontent.com/u/2895470?v=4)](https://github.com/colshrapnel "colshrapnel (2 commits)")

---

Tags

debugsqlpdoquerydebuggerreplacementPDOStatementdrop-in

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xsuchy09-e-pdostatement/health.svg)

```
[![Health](https://phpackages.com/badges/xsuchy09-e-pdostatement/health.svg)](https://phpackages.com/packages/xsuchy09-e-pdostatement)
```

###  Alternatives

[noahheck/e_pdostatement

Drop in replacement for default PDOStatement class allowing devs to view an interpolated version of a parameterized query

5121.2k](/packages/noahheck-e-pdostatement)[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)[panique/pdo-debug

A super-simple function that returns the full SQL query from your PDO statements

70106.5k3](/packages/panique-pdo-debug)[izniburak/pdox

Useful Query Builder, PDO Class for PHP. A simple access to your SQL records.

30221.1k7](/packages/izniburak-pdox)[atlas/query

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

41249.0k6](/packages/atlas-query)[filisko/pdo-plus

PDO+ extends PDO in order to log all your queries. It also includes a Bar Panel for Tracy

1920.5k](/packages/filisko-pdo-plus)

PHPackages © 2026

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