PHPackages                             opstops/pw - 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. opstops/pw

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

opstops/pw
==========

PHP PDO wrapper + ORM. Fast, lightweight, flexible and no dependencies!

220PHP

Since Dec 26Pushed 6y ago2 watchersCompare

[ Source](https://github.com/opstops/pw)[ Packagist](https://packagist.org/packages/opstops/pw)[ RSS](/packages/opstops-pw/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PDO Wrapper + ORM
=================

[](#pdo-wrapper--orm)

Fast, lightweight, flexible and no dependencies!

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

[](#installation)

Before using in your project, add it to your `composer.json` file:

```
$ ./composer.phar require require "opstops/pw: dev-master"
```

or use `composer.json` settings:

```
"minimum-stability": "dev",
"prefer-stable" : true
```

Usage
-----

[](#usage)

Creating a `PDO` instance:

```
require __DIR__ . '/../vendor/autoload.php';

use OpstopsPw\QueryBuilder as qb;
use OpstopsPw\Database;
use OpstopsPw\RowInterface;

$db = Database::get([
    'dsn' => 'mysql:host=127.0.0.1;dbname=db;charset=utf8',
    'username' => 'admin',
    'password' => 'admin',
    'options' => [
        // PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,..
    ]
]);
```

### Examples

[](#examples)

#### ORM

[](#orm)

```
echo '';
$q = qb::select('SELECT * FROM users')->where(['id' => 110])->order('username ASC, id DESC')->limit(5)->group('id')->offset(6);
var_dump($q->build()->sql); // SELECT * FROM users WHERE id = :id GROUP BY id ORDER BY username ASC, id DESC LIMIT 5 OFFSET 6

$q = qb::select('SELECT *')->from('users')->order(['username ASC', 'id DESC'])->limit(5)->offset(6);
var_dump($q->build()->sql); // SELECT * FROM users ORDER BY username ASC, id DESC LIMIT 5 OFFSET 6

$q = qb::select("* FROM users WHERE id=:id", [':id' => 12]);
var_dump($q->build()); // SELECT * FROM users WHERE id=:id

for other queries
$q = qb::query("CREATE TABLE IF NOT EXISTS tasks...");
var_dump($q->build()->sql); // CREATE TABLE IF NOT EXISTS tasks...
```

DB queries
----------

[](#db-queries)

```
$q = qb::select("SELECT username, id FROM users WHERE id > :id ", ['id' => 15])->limit(3);
var_dump($q->build()->sql); // CREATE TABLE IF NOT EXISTS tasks...

$res = $db->findAll($q);

//Array
//(
//[0] => stdClass Object
//(
//[username] => Lew
//[id] => 16
//)
//
//[1] => stdClass Object
//(
//[username] => Chlo
//[id] => 17
//)
//
//[2] => stdClass Object
//(
//[username] => Brittan
//[id] => 18
//)
//
//)

$res = $db->findAll($q, PDO::FETCH_ASSOC);

//Array
//(
//[0] => Array
//(
//[username] => Lew
//[id] => 16
//)
//
//[1] => Array
//(
//[username] => Chlo
//[id] => 17
//)
//
//[2] => Array
//(
//[username] => Brittan
//[id] => 18
//)
//
//)

class RowModel implements RowInterface {}
$res = $db->findAll($q, RowModel::class);

//Array
//(
//[0] => RowModel Object
//(
//[username] => Lew
//[id] => 16
//)
//
//[1] => RowModel Object
//(
//[username] => Chlo
//[id] => 17
//)
//
//[2] => RowModel Object
//(
//[username] => Brittan
//[id] => 18
//)
//
//)

$res = $db->findCol($q);
//Array
//(
//[0] => Lew
//[1] => Chlo
//[2] => Brittan
//)

$res = $db->findAssoc($q);

//Array
//(
//    [Lew] => 16
//    [Chlo] => 17
//    [Brittan] => 18
//)

$res = $db->findRow($q, PDO::FETCH_ASSOC);
//Array
//(
//    [username] => Lew
//    [id] => 16
//)

//$res = $db->findOne($q);
//Lew

$res = $db->findOne(qb::select('NOW()'));
print_r($res);

$q = qb::select("SELECT username, id")->from('users')->where([qb::RAW => 'username IS NOT NULL AND 1', 'id' => ['>', 3] ])->limit(3);
var_dump($q->build()->sql);
$res = $db->findAll($q);
print_r($res);

$q->toCount();
$res = $db->findOne($q); // 997
print_r($res);

$res = $db->findCount($q); // 997
print_r($res);

$q = qb::insert('users2', [
   'username' => 'Alex-'.random_int(0, 9999),
   'email' => 'Email@host.xx',
   'password' => password_hash(random_bytes(32), PASSWORD_DEFAULT)
]);
print_r($q->build());
$res = $db->run($q); // return last insert id
var_dump($res);

$res = $db->runDebug($q); // pdo statement debug
var_dump($res);

INSERT INTO users2 (username,email,password,created_at,updated_at) VALUES (:username, :email, :password, :created_at, :updated_at)

//[:username] => Alex-8299
//[:email] => Email@host.xx
//[:password] => $2y$10$yLsgth8Q.IcizeFuX/B4LeQ08qi3BRZ1/B9P78E/1V72X.oMSgiZK
//[:created_at] => 2019-10-23 12:38:27
//[:updated_at] => 2019-10-23 12:38:27

$qb = qb::update('users2', [
   'username' => 'Alex __ NEW__10',
], [
   'id' => 10
]);
var_dump($qb->build()->sql); // UPDATE users2 SET username = :username, updated_at = :updated_at WHERE id = :id

$res = $db->run($qb); // rows affected
var_dump($res);
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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/9c6618cd18bc2ca299f907ae4e6bebab34c5bbd9f9f99a22569f9b3a8489f38f?d=identicon)[opstops](/maintainers/opstops)

### Embed Badge

![Health badge](/badges/opstops-pw/health.svg)

```
[![Health](https://phpackages.com/badges/opstops-pw/health.svg)](https://phpackages.com/packages/opstops-pw)
```

###  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.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

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

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/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)
