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

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

royallthefourth/smooth-pdo
==========================

A drop-in PDO wrapper that provides smooth and pleasant method chaining

v2.0(9y ago)3751MITPHP ^7.0

Since Mar 23Compare

[ Source](https://github.com/royallthefourth/smooth-pdo)[ Packagist](https://packagist.org/packages/royallthefourth/smooth-pdo)[ RSS](/packages/royallthefourth-smooth-pdo/feed)WikiDiscussions Synced 6d ago

READMEChangelog (1)DependenciesVersions (3)Used By (1)

smooth-pdo
==========

[](#smooth-pdo)

A drop-in PDO wrapper that provides smooth and pleasant method chaining.

Rationale
---------

[](#rationale)

PDO is a perfectly fine way to access a database, but it would be a little more pleasant to work with if all the methods could be chained together. Unfortunately, you can't do that with PDO since it uses boolean return values to indicate errors. This just overrides the methods that use return values to indicate errors so they throw exceptions instead.

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

[](#installation)

`composer require royallthefourth/smooth-pdo`

Now create a `SmoothPdo\DataObject` from a `\PDO` and you're all set:

```
new RoyallTheFourth\SmoothPdo\DataObject(\PDO $db)
```

Example
-------

[](#example)

A typical example from the PDO documentation looks like this:

```
$calories = 150;
$colour = 'red';

$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour');
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
$sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);
$sth->execute();
```

Here's how it looks with `SmoothPdo\DataObject`:

```
