PHPackages                             migliori/php-pdo-database-class - 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. migliori/php-pdo-database-class

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

migliori/php-pdo-database-class
===============================

The DB class is a database abstraction layer that provides a simple, consistent interface for interacting with different types of databases. It handles connection management, query execution, pagination and result processing

v1.1(2y ago)4435GPL-3.0-or-laterPHPPHP &gt;=7.4

Since Nov 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/migliori/php-pdo-db-class)[ Packagist](https://packagist.org/packages/migliori/php-pdo-database-class)[ RSS](/packages/migliori-php-pdo-database-class/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

\[DEPRECATED\] PHP PDO Database class
=====================================

[](#deprecated-php-pdo-database-class)

[![Static Badge](https://camo.githubusercontent.com/50253820e667ebcce325162d9a3d1bde05baf1f58f5be6e8ddd5ebc3ce86a021/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706870253230372e342b2d6661666166613f6c6f676f3d706870)](https://camo.githubusercontent.com/50253820e667ebcce325162d9a3d1bde05baf1f58f5be6e8ddd5ebc3ce86a021/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706870253230372e342b2d6661666166613f6c6f676f3d706870) [![GPLv3 License](https://camo.githubusercontent.com/da9c3abfd62c32a94031c3a382cb7c85dbd4cede411416837adfe6b8fda05ba1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076332d79656c6c6f772e737667)](https://opensource.org/licenses/)

> ⚠️ **DEPRECATION NOTICE**: This package is no longer maintained and has been deprecated. It's been replaced by [PowerLite PDO](https://www.powerlitepdo.com). Please visit the [PowerLite PDO GitHub repository](https://github.com/migliori/power-lite-pdo) for the latest updates and support.

This DB class provides a set of simple, intuitive methods for executing queries and retrieving data. It handles pagination, error handling and debugging.

The code is fully documented with PHPDOC. It provides types &amp; type hinting and follows the highest coding standards (PHPSTAN Level 9).

Demo
----

[](#demo)

[PDO Database class - queries and pagination demos](https://www.phpformbuilder.pro/phpformbuilder/vendor/migliori/php-pdo-database-class/examples/select.php)

Features
--------

[](#features)

- Connection to any MySQL, Firebird, OCI (Oracle) or Pgsql (PostgreSQL) database
- SQL queries Sending
- Generation and sending of prepared PDO queries
- Functions available for all types of queries:
    - Select
    - SelectCount
    - SelectRow
    - SelectValue
    - Query
    - QueryRow
    - QueryValue
    - Execute
    - Insert
    - Update
    - Delete
    - GetColums
    - GetColumnsNames
    - GetTables
    - TransactionBegin
    - TransactionCommit
    - TransactionRollback
- Pagination with configuration and options
- Register your connection settings in a single safe place
- DEBUG mode - display of SQL queries sent to the server and detailed information
- Error event handling and PHP error logging with try/catch

Requirements
------------

[](#requirements)

PHP ^7.4, PHP 8.x

Documentation
-------------

[](#documentation)

[PHP PDO Database class - Full detailed documentation, functions reference &amp; code samples](https://www.phpformbuilder.pro/documentation/php-pdo-database-class.php)

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

[](#installation)

Clone / download or install with Composer

```
  composer require migliori/php-pdo-database-class
```

Usage/Examples
--------------

[](#usageexamples)

1. Open `src/connect/db-connect.php` in your code editor and set the followings constants to connect to your database:

    ```
    PDO_DRIVER // 'mysql', 'firebird', 'oci' or 'pgsql'
    DB_HOST    // For instance 'localhost'
    DB_NAME    // Your database name
    DB_USER    // Your database username
    DB_PASS    // Your database password
    DB_PORT[OPTIONAL]    // The default port is 3306
    ```
2. Require `src/connect/db-connect.php` and you can connect to both your localhost and production server using `$db = new DB();` without any argument.

    ```
    use Migliori\Database\Db;

    // register the database connection settings
    require_once 'src/connect/db-connect.php';

    // Then connect to the database
    $db = new DB();

    // or connect and show all the encountered errors automatically
    $db = new DB(true);

    // or connect, then test the connection and retrieve the error if the database is not connected
    $db = new DB();
    if (!$db->isConnected()) {
        $error_message = $db->error();
    }
    ```
3. Call the methods to send your queries and retrieve the results.

    ```
    // Select rows without using SQL
    $values = array('id', 'first_name', 'last_name');
    $where = array('country' => 'Indonesia');
    $db->select('customers', $values, $where);

    // We can make more complex where clauses in the Select, Update, and Delete methods
    $values = array('id', 'first_name', 'last_name');
    $where = array(
        'zip_code IS NOT NULL',
        'id >' => 10,
        'last_name LIKE' => '%Ge%'
    );
    $db->select('customers', $values, $where);

    // Let's sort by descending ID and run it in debug mode
    $extras = array('order_by' => 'id DESC');
    $db->select('customers', $values, $where, $extras, true);

    // loop through the results
    while ($row = $db->fetch()) {
        echo $row->first_name . ' ' . $row->last_name . '';
    }

    // or fetch all the records then loop
    // (this function should not be used if a huge number of rows have been selected, otherwise it will consume a lot of memory)
    $rows = $db->fetchAll();

    foreach ($rows as $row) {
        echo $row->first_name . ' ' . $row->last_name . '';
    }
    ```

To see all the public methods and more examples of use of use visit

Example with Pagination
-----------------------

[](#example-with-pagination)

1. Open `database/db-connect.php` in your code editor and set the followings constants to connect to your database:

    ```
    PDO_DRIVER // 'mysql', 'firebird', 'oci' or 'pgsql'
    DB_HOST    // For instance 'localhost'
    DB_NAME    // Your database name
    DB_USER    // Your database username
    DB_PASS    // Your database password
    DB_PORT[OPTIONAL]    // The default port is 3306
    ```
2. Get your records and the pagination HTML code

    ```
    use Migliori\Database\Pagination;
    use Migliori\Database\PdoSelectParams;

    // register the database connection settings
    require_once 'src/connect/db-connect.php';

    // register the PDO parameters for the query in a PdoSelectParams() object
    $values = array('id', 'first_name', 'last_name');
    $where = array('country' => 'Indonesia');

    $pdo_select_params = new PdoSelectParams('customers', $values, $where);

    // create the Pagination object
    $db = new Pagination($pdo_select_params);

    // get the records and the pagination HTML code
    $pagination_html = $db->pagine();

    // count the records and display them
    $records_count = $db->rowCount();

    if (!empty($records_count)) {
        while ($row = $db->fetch()) {
            echo $row->first_name . ' ' . $row->last_name . ' : ' . $row->country . '';
        }
    }

    echo $pagination_html;
    ```

Running Tests
-------------

[](#running-tests)

To run tests, run the following command

```
php ./vendor/bin/phpunit test
```

Contributing
------------

[](#contributing)

Contributions are always welcome!

Please contact us for any improvement suggestions or send your pull requests

License
-------

[](#license)

[GNU General Public License v3.0](https://choosealicense.com/licenses/gpl-3.0/)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

802d ago

PHP version history (2 changes)v1.0PHP &gt;=7.3

v1.1PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/82cd171f848f6e6fc792344b87070bebaee163b5719cc7166d0ebf1fcfff2b58?d=identicon)[migli](/maintainers/migli)

---

Top Contributors

[![migliori](https://avatars.githubusercontent.com/u/7558100?v=4)](https://github.com/migliori "migliori (14 commits)")

---

Tags

databasefirebirdmysqlocipaginationpdopdo-mysqlphppostgresql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/migliori-php-pdo-database-class/health.svg)

```
[![Health](https://phpackages.com/badges/migliori-php-pdo-database-class/health.svg)](https://phpackages.com/packages/migliori-php-pdo-database-class)
```

###  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)
