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

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

lehbyos/super-pdo
=================

Utility class, created as a wrapper to PDO

00PHP

Since Sep 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Lehbyos/superPDO)[ Packagist](https://packagist.org/packages/lehbyos/super-pdo)[ RSS](/packages/lehbyos-super-pdo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SuperPDO
========

[](#superpdo)

Wrapper class to PDO, with helper methods to common task in CRUD operations

General purpose
---------------

[](#general-purpose)

This class provides a very thin layer over PDO, giving some helpful methods to manipulate data.

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

[](#configuration)

SuperPDO has a singleton implementation, and can manage multiple database connections, identifying every one of them with a name.

As a convention, SuperPDO asumes that the main connection is called *default*, using that name as a default value.

To add a new connection to SuperPDO, you must use the static addConnection() method.

```
SuperPDO::addConnection(string $name, string $dsn, ?string $username = null, ?string $password = null)

```

- **$name** is the name (alias) of the connection.This name must be unique, and SuperPDO will throw an exception if the name was already added.
- **$dsn** is the connection string, as required by PDO.
- **$username** and **$password** are the login data to the database, if required.

The connections have *lazy initialization*, thus they are created only when required by the connection() method.

```
SuperPDO::connection(string $name = "default"): SuperPDO

```

This is the method to get a connection, with the given name. This call will throw an exception if there is no connection with the given name, or if the connection could not be fulfilled.

### Getting data

[](#getting-data)

#### Multiple rows

[](#multiple-rows)

It's a very common scenario to perform the next steps to get some data from PDO:

```
//$conn is a PDO instance.
$stmt = $conn->prepare('select * from some_table where some_field = :value and other_field = :other_value');
$stmt->bindValue(':value' => $value1);
$stmt->bindValue(':other_value' => $value2);
if (!$stmt->execute()){
  //handle the error, free resources
}
$data = array();
while($obj = $stmt->fetchObject()){
  $resp[] = $obj;
}
$stmt->closeCursor();

//$data has all the data

```

On every query, you must to repeat this lines, creating a lot of boilerplate code.

With superPDO, all the code above can be rewritten as

```
//Asumming that SuperPDO only have a connection configured with the name "default"
try{
  $data = SuperPDO::connection()->selectQuery(
    'select * from some_table where some_field = :value and other_field = :other_value',
    [':value' => $value1, ':other_value' => $value2]
  );
}
catch(Exception $e){
   //handle error; an exception will be throw if the SQL has error or if the execution of the statement fails
}

```

As you can see, the last code is cleaner and shorter than the first one.

The parameters could also be positional (not named), witch generate even shorter code.

```
try{
  $data = SuperPDO::connection()->selectQuery(
    'select * from some_table where some_field = ? and other_field = ?',
    [$value1, $value2]
  );
}
catch(Exception $e){
   //handle error; an exception will be throw if the SQL has error or if the execution of the statement fails
}

```

#### One data row

[](#one-data-row)

SuperPDO can get just one data row.

```
try{
  $usr = SuperPDO::connection()->singleRowQuery('select * from users where user_id = ?', [$id]);
}
catch(Exception $e){
   //handle error; an exception will be throw if the SQL has error or if the execution of the statement fails
}

```

In a very restrictive way, SuperPDO can ensure that a query just create ONE row, throwing and exception if the query gives zero or more than one data row.

```
try{
  $usr = SuperPDO::connection()->uniqueRowQuery('select * from users where user_creation_date = ?', [$date]);
}
catch(Exception $e){
   //handle error; an exception will be throw if the SQL has error or if the execution of the statement fails
}

```

### Inserting, updating or deleting data

[](#inserting-updating-or-deleting-data)

Insert, update or delete data from a database usually requires almost the same steps to be performed.

```
//$conn is a PDO instance
$stmt = $conn->prepare('insert into my_table values(:field1, :field2, :field3, :field4, :field5');
$stmt->bindValue(':field1' => $value1);
$stmt->bindValue(':field2' => $value2);
$stmt->bindValue(':field3' => $value3);
$stmt->bindValue(':field4' => $value4);
$stmt->bindValue(':field5' => $value5);

$rows = $stmt->execute();
if ($rows === false){
  //error executing SQL; handle this
}
if ($rows !== 1){
  //usually, PDO return the number of affected rows; 1 insert means that 1 rows should be affected.
  //if that is not the case, then an error has occurred; handle it.
}

//the rest of your code

```

The same result can be achieved with superPDO on this way

```
try{
  $rows = SuperPDO::connection()->executeStatement(
    'insert into my_table values(:field1, :field2, :field3, :field4, :field5',
    [':field1' => $value1, ':field2' => $value2, ':field3' => $value3, ':field4' => $value4, ':field5' => $value5]
  );
  if ($rows !== 1){
    //Rows affected doesn't match with the current operation
  }
}
catch(Exception $e){
  //Execution error of the SQL statement; handle it.
}

```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/25fd79709e0faddcfd4643de749ed634dbf31bdfd4292c2b51946a6e1c144e7d?d=identicon)[Lehbyos](/maintainers/Lehbyos)

---

Top Contributors

[![Lehbyos](https://avatars.githubusercontent.com/u/1282172?v=4)](https://github.com/Lehbyos "Lehbyos (11 commits)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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