PHPackages                             jpi/database - 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. jpi/database

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

jpi/database
============

Simple extension to PDO

v2.0.0(2y ago)04.5k↓87.5%2GPL-3.0-onlyPHPPHP ^7.1 || ^8.0CI passing

Since Mar 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/jahidulpabelislam/database)[ Packagist](https://packagist.org/packages/jpi/database)[ RSS](/packages/jpi-database/feed)WikiDiscussions 2.x Synced 1w ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (2)

Database
========

[](#database)

[![CodeFactor](https://camo.githubusercontent.com/71c833134f3c14406bfdf38aae798d73d185348e4ba8a618c7d119946a858f62/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a61686964756c706162656c69736c616d2f64617461626173652f6261646765)](https://www.codefactor.io/repository/github/jahidulpabelislam/database)[![Latest Stable Version](https://camo.githubusercontent.com/b2b14aa3897dc548d58302626a447c9aca57857f52548b4072e4915c472e4cc0/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f64617461626173652f762f737461626c65)](https://packagist.org/packages/jpi/database)[![Total Downloads](https://camo.githubusercontent.com/7915fce678b5b7f48fe2b55425fffc54ba3cc0891fe2c6d84cb8c713a45d0a5d/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f64617461626173652f646f776e6c6f616473)](https://packagist.org/packages/jpi/database)[![Latest Unstable Version](https://camo.githubusercontent.com/accd981ff378872c3e6b8982d630978dd1efa2f96c245eae081d68ef5a88a64c/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f64617461626173652f762f756e737461626c65)](https://packagist.org/packages/jpi/database)[![License](https://camo.githubusercontent.com/88e07225f30bff36ca6c3acd3c9a3991d031db3ec41a330a6bb2205209cf6100/68747470733a2f2f706f7365722e707567782e6f72672f6a70692f64617461626173652f6c6963656e7365)](https://packagist.org/packages/jpi/database)[![GitHub last commit (branch)](https://camo.githubusercontent.com/4f0ece84c89b7b9533171031eb9305d20bb6fb4708320946ddc840a296e3fdef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6a61686964756c706162656c69736c616d2f64617461626173652f322e782e7376673f6c6162656c3d6c6173742532306163746976697479)](https://camo.githubusercontent.com/4f0ece84c89b7b9533171031eb9305d20bb6fb4708320946ddc840a296e3fdef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6a61686964756c706162656c69736c616d2f64617461626173652f322e782e7376673f6c6162656c3d6c6173742532306163746976697479)

Simple extension to `PDO` with some extra convenient methods including simplified parameter binding and easy data fetching. Fully compatible with standard PDO usage, making it easy to use as a drop-in replacement.

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

[](#installation)

Use [Composer](https://getcomposer.org/)

```
$ composer require jpi/database
```

Usage
-----

[](#usage)

### Initialisation

[](#initialisation)

First, create an instance of the Database class by providing PDO connection parameters:

```
$connection = new \JPI\Database(
    "mysql:host=localhost;dbname=your_database",
    "username",
    "password"
);
```

### Available Methods

[](#available-methods)

Extra Methods:

- `prep(string, array): PDOStatement`: when you want to bind some parameters to a query
- `run(string, array): PDOStatement`: when you bind some parameters to a query and want to execute it
- `selectAll(string, array): array`: for a `SELECT` query, returns a multidimensional array of all the rows found
- `selectFirst(string, array): array|null`: for a `SELECT` query that has `LIMIT 1`, returns an associative array of the first row found (if any)
- `getLastInsertedId(): int|null`: helpful after an `INSERT` query, returns the ID of the newly inserted row

Overridden Methods:

- `exec(string, array): int`: for `INSERT`, `UPDATE` and `DELETE` queries, returns the number of rows affected

All methods except `getLastInsertedId` take the query as the first parameter (required), and an array of params to bind to the query (optional).

### Examples:

[](#examples)

(Assuming instance has been created and set to a variable named `$connection`)

#### prep:

[](#prep)

```
// Prepare a statement with bound parameters (without executing)
$statement = $connection->prep(
    "SELECT * FROM users WHERE email = :email;",
    ["email" => "jahidul@jahidulpabelislam.com"]
);

// You can now execute it later
$statement->execute();
```

#### run:

[](#run)

```
// Prepare and execute a query in one step
$statement = $connection->run(
    "SELECT * FROM users WHERE email = :email;",
    ["email" => "jahidul@jahidulpabelislam.com"]
);

// Fetch results from the statement
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
```

#### selectAll:

[](#selectall)

```
$rows = $connection->selectAll("SELECT * FROM users;");

/**
$rows = [
    [
        "id" => 1,
        "first_name" => "Jahidul",
        "last_name" => "Islam",
        "email" => "jahidul@jahidulpabelislam.com",
        "password" => "password123",
        ...
    ],
    [
        "id" => 2,
        "first_name" => "Test",
        "last_name" => "Example",
        "email" => "test@example.com",
        "password" => "password123",
        ...
    ],
    ...
];
*/
```

#### selectFirst:

[](#selectfirst)

```
$row = $connection->selectFirst("SELECT * FROM users LIMIT 1;");

/**
$row = [
    "id" => 1,
    "first_name" => "Jahidul",
    "last_name" => "Islam",
    "email" => "jahidul@jahidulpabelislam.com",
    "password" => "password",
    ...
];
*/
```

#### exec:

[](#exec)

```
// INSERT
$numberOfRowsAffected = $connection->exec(
    "INSERT INTO users (first_name, last_name, email, password) VALUES (:first_name, :last_name, :email, :password);",
    [
        "first_name" => "Jahidul",
        "last_name" => "Islam",
        "email" => "jahidul@jahidulpabelislam.com",
        "password" => "password",
    ]
);

// UPDATE
$numberOfRowsAffected = $connection->exec(
    "UPDATE users SET first_name = :first_name WHERE id = :id;",
    [
        "id" => 1,
        "first_name" => "Pabel",
    ]
);

// DELETE
$numberOfRowsAffected = $connection->exec("DELETE FROM users WHERE id = :id;", ["id" => 1]);
```

#### getLastInsertedId:

[](#getlastinsertedid)

```
// INSERT a new user
$connection->exec(
    "INSERT INTO users (first_name, last_name, email, password) VALUES (:first_name, :last_name, :email, :password);",
    [
        "first_name" => "Jahidul",
        "last_name" => "Islam",
        "email" => "jahidul@jahidulpabelislam.com",
        "password" => "password",
    ]
);

// Get the ID of the newly inserted row
$newRowId = $connection->getLastInsertedId();
// $newUserId = 3
```

Support
-------

[](#support)

If you found this library interesting or useful please spread the word about this library: share on your socials, star on GitHub, etc.

If you find any issues or have any feature requests, you can open a [issue](https://github.com/jahidulpabelislam/database/issues) or email [me @ jahidulpabelislam.com](mailto:me@jahidulpabelislam.com) 😏.

Authors
-------

[](#authors)

- [Jahidul Pabel Islam](https://jahidulpabelislam.com/) [](mailto:me@jahidulpabelislam.com)

Licence
-------

[](#licence)

This module is licensed under the General Public Licence - see the [licence](LICENSE.md) file for details.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance51

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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 ~250 days

Recently: every ~366 days

Total

8

Last Release

141d ago

Major Versions

v1.1.3 → v2.0.0-beta.12023-03-19

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.1.3PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3eb53275639d93b5fdae3b835527fdb958dbc1214e58a97d10fa50fe66a836cd?d=identicon)[jahidulpabelislam](/maintainers/jahidulpabelislam)

---

Top Contributors

[![jahidulpabelislam](https://avatars.githubusercontent.com/u/15434150?v=4)](https://github.com/jahidulpabelislam "jahidulpabelislam (61 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (4 commits)")

---

Tags

databasemysqlpdophpdatabasemysqlpdodb

### Embed Badge

![Health badge](/badges/jpi-database/health.svg)

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

###  Alternatives

[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41234.1k4](/packages/aura-sqlschema)

PHPackages © 2026

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