PHPackages                             phossa/phossa-db - 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. phossa/phossa-db

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

phossa/phossa-db
================

A PHP db libraray

1.0.2(10y ago)133MITPHPPHP &gt;=5.4.0

Since Apr 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/phossa/phossa-db)[ Packagist](https://packagist.org/packages/phossa/phossa-db)[ Docs](https://github.com/phossa/phossa-db)[ RSS](/packages/phossa-phossa-db/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

phossa-db
=========

[](#phossa-db)

[![Build Status](https://camo.githubusercontent.com/350ab8f8977ba8a7f6ac75fde8d4d34759252a91fa82616877eede6a056c9e31/68747470733a2f2f7472617669732d63692e6f72672f70686f7373612f70686f7373612d64622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa/phossa-db)[![HHVM](https://camo.githubusercontent.com/3dfa391d3166128fc8807a0a4a547371176d8904b5b7e3aea81a7a689ac8af25/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f7373612f70686f7373612d64622e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa/phossa-db)[![Latest Stable Version](https://camo.githubusercontent.com/e49022ddd75e6077267d9fd76f88d1f3502fd62a192201c973224b7dff3bc78f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f7373612f70686f7373612d64622e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa/phossa-db)[![License](https://camo.githubusercontent.com/dca682dfc8c59fd42c76a4dcf4a2292ad1cc557e7b604eb5e330e11227bd6f70/68747470733a2f2f706f7365722e707567782e6f72672f70686f7373612f70686f7373612d64622f6c6963656e7365)](http://mit-license.org/)

Introduction
------------

[](#introduction)

*phossa-db* is a PHP db connection management library which handles the interaction with db.

It requires PHP 5.4 and supports PHP 7.0+, HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader").

Features
--------

[](#features)

- Simple interface. Nothing you don't need.
- Multiple db platform/driver support, currently PDO (all PDO drivers) and Mysqli.
- Handles multiple connections through driver manager

    - Round-robin load balancing

        Multiple db connections are used in round-robin fashion and weighting factor (1-10) supported. Each connection is monitored (pinged).
    - driver tagging, so user can tag different db connection as 'reader' or 'writer'
- Easy profiling, get each executed sql and its execution time.
- Secure. All SQL executed through prepare/execute in low-level drivers.

Getting started
---------------

[](#getting-started)

- **Installation**

    Install via the [`composer`](https://getcomposer.org/) utility.

    ```
    composer require "phossa/phossa-db=1.*"

    ```

    or add the following lines to your `composer.json`

    ```
    {
        "require": {
          "phossa/phossa-db": "1.*"
        }
    }
    ```

Usage
-----

[](#usage)

- Driver

    - DDL using execute()

        ```
        $db = new Phossa\Db\Pdo\Driver([
            'dsn' => 'mysql:dbname=test;host=127.0.0.1;charset=utf8'
        ]);

        // simple delete
        $res = $db->execute("DELETE FROM test WHERE id < 10");
        if (false === $res) {
          	echo $db->getError() . \PHP_EOL;
        } else {
          	echo sprintf("Deleted %d records", $res) . \PHP_EOL;
        }

        // with parameters
        $res = $db->execute("INSERT INTO test (name) VALUES (?)", [ 100 ]);
        if ($res) {
        	$id = (int) $db->getLastInsertId();
        }
        ```
    - SELECT using query()

        ```
        // simple select
        $res = $db->query("SELECT * FROM test WHERE id < 10");
        if (false === $res) {
          	echo $db->getError() . \PHP_EOL;
        } else {
          	$rows = $res->fetchAll();
        }

        // with parameters & fetch first 5 rows
        $res = $db->query("SELECT * FROM test WHERE id > ? LIMIT ?", [10, 20]);
        if ($res && $res->isQuery()) {
        	$firstFiveRows = $res->fetchRow(5);
        }

        // fetch first field
        $res = $db->query("SELECT id, name FROM test WHERE id < :id", ['id' => 10]);
        if ($res && $res->isQuery()) {
        	$firstCols = $res->fetchCol('id');
        }
        ```
- Statment

    `Statement` is returned by `$db->prepare()`.

    ```
    // PREPARE using prepare()
    $stmt = $db->prepare("SELECT * FROM test WHERE id < :id");
    if (false === $stmt) {
        echo $db->getError() . \PHP_EOL;
    } else {
        $res = $stmt->execute(['id' => 10]);
        if (false === $res) {
           echo $db->getError() . \PHP_EOL;
        } else {
           $rows = $res->fetchAll();
        }
    }
    ```
- Result

    `Result` is returned by `$db->execute()`, `$db->query()` or `$stmt->execute()`

    ```
    $res = $db->query(...);
    if ($res) {
        // SELECT
        if ($res->isQuery()) {
            // get fields count
            $fieldCount = $res->fieldCount();
            // row count
            $rowCount   = $res->rowCount();

        // DDL
        } else {
            $affectedRows = $res->affectedRows();
        }
    }
    ```

Driver manager
--------------

[](#driver-manager)

Driver manager manages multiple db connections. Weighting factor N means add one driver virtually N times. Adding driver *A* with factor 5 and adding driver *B* with factor 1 into the pool, means when calling `getDriver()`, user will get *A* five times vs *B* for one time.

```
// writable connect 1
$db1 = (new Phossa\Db\Pdo\Driver($conf1))->addTag('RW');

// dbreader 2
$db2 = (new Phossa\Db\Pdo\Driver($conf2))->addTag('RO');

// dbreader 3
$db3 = (new Phossa\Db\Pdo\Driver($conf3))->addTag('RO');

// db manager
$dbm = (new Phossa\Db\Manager\Manager())
    ->addDriver($db1, 1)    // writable connection with factor 1
    ->addDriver($db2, 5)	// read_only, factor 5
    ->addDriver($db3, 5)	// read_only, factor 5

// get a db connect, no matter writable or read only
$db = $dbm->getDriver();

// get a readonly driver
$db = $dbm->getDriver('RO');

```

SQL profiling
-------------

[](#sql-profiling)

Get the executed SQL and its execution time.

```
// init driver
$db = new Phossa\Db\Pdo\Driver($conf);

// enable profiling
$db->enableProfiling();

// execute a DELETE
$db->execute("DELETE FROM test WHERE test_id > 10");

// get sql
$sql  = $db->getProfiler()->getSql();
$time = $db->getProfiler()->getExecutionTime();
```

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa/phossa-shared ~1.0.10

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3673d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f8140b30658c77b72e1596e6cbc4cf1cd9b308f636a8adf125d09af74ee52124?d=identicon)[phossa](/maintainers/phossa)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (31 commits)")

---

Tags

databasedbphossardbm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phossa-phossa-db/health.svg)

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

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M401](/packages/robmorgan-phinx)[spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

8362.9M51](/packages/spatie-laravel-translation-loader)[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)[lichtner/fluentpdo

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

921274.8k6](/packages/lichtner-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)

PHPackages © 2026

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