2017 © Pedro Peláez
 

library smooth-pdo

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

image

royallthefourth/smooth-pdo

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

  • Sunday, June 11, 2017
  • by royallthefourth
  • Repository
  • 1 Watchers
  • 1 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

smooth-pdo

A drop-in PDO wrapper that provides smooth and pleasant method chaining., (*1)

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., (*2)

Installation

composer require royallthefourth/smooth-pdo, (*3)

Now create a SmoothPdo\DataObject from a \PDO and you're all set:, (*4)

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

Example

A typical example from the PDO documentation looks like this:, (*5)

$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:, (*6)

<?php
$calories = 150;
$colour = 'red';

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

Differences from PDO

This library works almost exactly like PDO. Just beware that these methods now throw exceptions instead of returning false: * PDO::beginTransaction * PDO::commit * PDO::rollback * PDO::setAttribute * PDOStatement::bindColumn * PDOStatement::bindParam * PDOStatement::bindValue * PDOStatement::closeCursor * PDOStatement::execute, (*7)

Problems

If you encounter any problems or notice any other divergence from PDO, please don't hesitate file an issue., (*8)

The Versions

11/06 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Royall Spence

11/06 2017

v2.0

2.0.0.0

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

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Royall Spence

23/03 2017

v1.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Royall Spence