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

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

commandstring/pdo
=================

A PDO driver with additional features

v3.1.1(3y ago)080MITPHP

Since Oct 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/CommandString/pdo)[ Packagist](https://packagist.org/packages/commandstring/pdo)[ RSS](/packages/commandstring-pdo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

This has been moved to [TNAPF](https://github.com/tnapf/pdo) and updates will no longer be made here
====================================================================================================

[](#this-has-been-moved-to-tnapf-and-updates-will-no-longer-be-made-here)

CommandString/Pdo
=================

[](#commandstringpdo)

Making PDO easier with the power of magic

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

[](#installation)

`composer require commandstring/pdo`

Creating a connection
=====================

[](#creating-a-connection)

Doing so manually
-----------------

[](#doing-so-manually)

```
$driver = (new Driver)
	->withUsername("root")
	->withPassword("password")
	->withDatabase("database")
	->withHost("127.0.0.1")
	->withPort(3306)
	->withPrefix(Driver::PREFIX_MYSQL)
	->connect()
;
```

*You can use Driver::setDsnProp or Driver::with{insert dsn prop name here} to set additional dsn values*

Using the database predefined createDriver method
-------------------------------------------------

[](#using-the-database-predefined-createdriver-method)

*I currently only have mysql and postgres specific methods*

```
$driver = Driver::createMySqlDriver("root", "password", "database")->connect();
$driver = Driver::createPostgresSqlDriver("root", "password", "database")->connect();

// you can set the host and port in the last two parameters but they default to localhost and the default port of the service
```

Executing a query
=================

[](#executing-a-query)

```
$rows = $driver->query("SELECT * FROM table")->fetchAll(PDO::FETCH_ASSOC);
```

The driver will store the PDOStatement internally and detect if the method your invoking exists in PDOStatement or PDO and invoke it on one of the instances accordinly. *Thankfully there's no method names that are the same between the two classes*

Preparing a statement
=====================

[](#preparing-a-statement)

```
$driver->prepare("SELECT * FROM table WHERE column = :column");
$driver->bindValue("column", "value");
$driver->execute();
$rows = $driver->fetchAll(PDO::FETCH_ASSOC);
```

Singleton Constructor Argument
==============================

[](#singleton-constructor-argument)

If you construct a Driver with the singleton argument as `true` then that new instance will be stored as a static property in the class that can be called from anywhere with the `get` method. You can additionally call PDO/PDOStatement methods statically from Driver and it will work similar to `$driver->methodName`

```
(new Driver(true))
	->withUsername("root")
	->withPassword("password")
	->withDatabase("database")
	->withHost("127.0.0.1")
	->connect()
;

function getRowWhereIdIs(int $id, int $fetch_type = PDO::FETCH_ASSOC): mixed
{
	Driver::prepare("SELECT * FROM table WHERE id = :id");
	Driver::bindValue("id", $id);
	Driver::execute();
	return Driver::fetch($fetch_type);
}

$row = getRowWhereIdIs(20);
```

Building Statements
===================

[](#building-statements)

Select
------

[](#select)

```
$driver->select()
    ->from("table")
    ->columns(["column" => "column_alias_name"], "column2")
    ->orderBy("column", "ASC")
    ->limit(20)
    ->offset(30)
;
```

Insert
------

[](#insert)

```
$driver->insert()
    ->into("table")
    ->value("column", "value")
    ->values(["column2" => "value", "column3" => "value"])
;
```

Update
------

[](#update)

```
$driver->update()
    ->table("table")
    ->set("column", "newValue")
    ->where("column", "=", "value")
;
```

Delete
------

[](#delete)

```
$driver->delete()
    ->from("table")
    ->where("column", "=", "value")
```

Using where method
------------------

[](#using-where-method)

```
// ...
->where("column", "=", "value")
->where("column", "IN", [1, 5, "hi"])
->where("column", "IN", [(new Select($driver))->from("table")->columns("column")])
->where("column", "BETWEEN", [0, 5])
->whereOr("column", "=", 5)
->whereNot("column", "=", 10)
```

Creating Storable Statements
============================

[](#creating-storable-statements)

Create storableStatement instance
---------------------------------

[](#create-storablestatement-instance)

```
$storableStmt = $driver->storableStatements->create("accounts.getByUsername")
```

Create statement to be stored
-----------------------------

[](#create-statement-to-be-stored)

```
$storableStmt->setStatement($driver->select()->from("accounts")->columns("name", "id"));
```

Set before handler (optional)
-----------------------------

[](#set-before-handler-optional)

```
$storableStmt->setBeforeHandler(function (Select $statement, string $name): Select
{
    return $statement->where("name", "=", $name);
});
```

The first argument is the statement passed into the setStatement method. You can define arguments that can be set when executing the statement *more on that later*.

Set after handler (optional)
----------------------------

[](#set-after-handler-optional)

```
$storableStmt->setAfterHandler(function (PDOStatement $statement)): Account
{
    $results = $statement->fetch(PDO::FETCH_OBJ);

    return new Account($results->name, $results->id);
}
```

Executing stored statement
--------------------------

[](#executing-stored-statement)

```
$driver->storableStatements->execute("accounts.getByUsername", ["Command_String"]);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~26 days

Total

6

Last Release

1192d ago

Major Versions

v1.0.1 → v2.0.02022-12-24

v2.0.0 → v3.0.02023-01-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1dc8515485fa64088fdfa03dd0f487d507dc1516824c31be2626a6ee25244dd?d=identicon)[command\_string](/maintainers/command_string)

---

Top Contributors

[![CommandString](https://avatars.githubusercontent.com/u/44886996?v=4)](https://github.com/CommandString "CommandString (5 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/commandstring-pdo/health.svg)](https://phpackages.com/packages/commandstring-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.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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