PHPackages                             dekyfin/easypdo - 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. dekyfin/easypdo

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

dekyfin/easypdo
===============

A convenient wrapper for PDO. Supports only MySQL at the moment

1.3.1(7y ago)117MITPHPPHP ^5.4.0 || ^7.0

Since Nov 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dekyfin/easypdo)[ Packagist](https://packagist.org/packages/dekyfin/easypdo)[ RSS](/packages/dekyfin-easypdo/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (5)Used By (0)

EasyPDO
=======

[](#easypdo)

A convenient wrapper for PDO. Supports only MySQL at the moment. It is meant to simplify common queries in order to reduce the code to be written.

Example
-------

[](#example)

```
// Insert row using prepared statement and get insert id
// PDO
$stmt = $db->prepare("INSERT INTO table(col1,col2) VALUES(:col1, :col2)");
$stmt->execute(["col1"=>"val1", "col2"=>"val2"]);
$id = $db->lastInsertId();

// EasyPDO
$id = $db->insert("table", ["col1" => "val1", "col2"=>"val2"]);

// Select rows from DB
//PDO
$stmt2 = $db->prepare("SELECT * FROM table WHERE col1 = :col1 AND col2 = :col2)");
$stmt2->execute(["col1"=>"val1", "col2"=>"val2"]);
$rows = $db->fetchAll( $stmt2 );

// EasyPDO
$rows = $db->select("table", ["col1"=>"val1", "col2"=>"val2"]);
```

What Can EasyPDO Do?
--------------------

[](#what-can-easypdo-do)

1. Convenient wrappers for all CRUD operations
    1. SELECT
    2. UPDATE
    3. INSERT
    4. DELETE
    5. INSERT/UPDATE
2. Easily get the insertId for INSERT, affected rows for UPDATE/DELETE, and array of rows for SELECT statements.

```
/*	Take note of the  the 2nd parameter:
*	A value of true ocauses the function to return the 'convenient data',
*	while false returns the PDOStatement Object
*/

// Select Statement
$rows = $db->execute("SELECT id FROM table WHERE id < :max", ["max"=>3], true);
// Output: array of matched rows

$insertId = $db->execute("INSERT INTO table(col1, col2) VALUES(:col1, :col2)", ["col1"=>"val1", "col2"=>"val2"], true);
//Output: inserId

$affectedRows = $db->execute("DELETE FROM table WHERE id = :id", ["id"=>5], true);
//Output: affected rows

$affectedRows = $db->execute("UPDATE table SET col1 = :col1 WHERE id = :id", ["id"=>5, "col1"=>"valX"], true);
//Output: affected rows
```

3. Use plain old PDO anytime you want

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

[](#installation)

### Composer

[](#composer)

```
composer require dekyfin/easypdo

```

### Manual

[](#manual)

1. Download the zip file
2. Include `src/DB.php` into your pr

```
require_once "/path/to/src/DB.php";
```

Usage
-----

[](#usage)

```
// Options for connecting to MySQL database
$options = [
	"host"=>"localhost",
	"user"=>"db_user",
	"db"=>"db_name",
	"pass"=>"s3cr3tp@ssw0rd"
];

// Create connection
$db = new DF\DB($options);

// Run queries
$rows = $db->query("SELECT * FROM table", true);
```

Methods
=======

[](#methods)

### select( string $table, array $conditions = \[\] , mixed $modifiers ): array $rows

[](#select-string-table-array-conditions----mixed-modifiers--array-rows)

Used to select rows matching some `$conditions`. This method currently selects all columns. It will be modified in v2.x.x to allow specifying of columns

- `$conditions` An associative array of `$column => $value` to match against. Uses SQL `AND` operator to match all `$conditions`
- `$modifiers` int || string
    - An integer will limit the number of results. Results in `LIMIT BY $modifiers`
    - A string which will be put at the end of the query to modify the behaviour. Example: `ORDER BY id DESC`

```
$data = $db->select("table", ["category"=>3] , 10); //Show only 10 results
$data = $db->select("table", ["category"=>3] , "ORDER BY id DESC");
```

### insert( string $table, array $values ): int $insertId

[](#insert-string-table-array-values--int-insertid)

### update( string $table, array $values = \[\] \[, array $conditions\] ): int $rowCount

[](#update-string-table-array-values----array-conditions--int-rowcount)

### insertUpdate( string $table, array $values ): int insertId

[](#insertupdate-string-table-array-values--int-insertid)

Note: This method will return the insertId of the row if insert or update worked successfully

### delete( string $table, array $conditions): int $rowCount

[](#delete-string-table-array-conditions-int-rowcount)

### query( string $sql , boolean $fetchAll = false )

[](#query-string-sql--boolean-fetchall--false-)

This function is used to run an sql query. Returns array of data if $fetchAll is true, and a PDOStatement object if false

```
$data = $db->query("Select id FROM table", true); // [ [id=>1], [id=>2] ... ]
```

### execute( string $sql, array $values , boolean $fetchAll = false )

[](#execute-string-sql-array-values--boolean-fetchall--false-)

Used to prepare and execute a statement. Useful for running a one-off prepared statement. Returns array of data if $fetchAll is true, and a PDOStatement object if false

```
$data = $db->execute("Select id FROM table WHERE id < :max", ["max"=>3] , true); // [ [id=>1], [id=>2] ... ]
```

### prepare( string $sql ): PDOStatement

[](#prepare-string-sql--pdostatement)

```
$stmt = $db->prepare("INSERT INTO table(col1,col2) VALUES(:col1, :col1)");

$stmt->execute(["col1" => 3, "col2" => 4 ]);
$stmt->execute(["col1" => 5, "col2" => 6 ]);
$stmt->execute(["col1" => 50, "col2" => 2e6 ]);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~0 days

Total

4

Last Release

2732d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/52e7a7eafed5abbe994adc036979571a91910e4a964902ab6e4a5844209f5a98?d=identicon)[dekyfin](/maintainers/dekyfin)

---

Top Contributors

[![dekyfin](https://avatars.githubusercontent.com/u/8211774?v=4)](https://github.com/dekyfin "dekyfin (9 commits)")

---

Tags

pdo-mysqlpdo-wrapperpdowrapperphp

### Embed Badge

![Health badge](/badges/dekyfin-easypdo/health.svg)

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

###  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.0M545](/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)
