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

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

objectiveweb/db
===============

Database Abstraction Layer and Management Frontend

v0.7.0(5y ago)13971[1 PRs](https://github.com/objectiveweb/db/pulls)MITPHPPHP &gt;=5.6.0CI failing

Since Dec 19Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (30)Used By (0)

DB [![Build Status](https://camo.githubusercontent.com/a43c8857cdafa46aa308e04ab403226f2b905fc21e16ab5681ab05716095f809/68747470733a2f2f7472617669732d63692e6f72672f6f626a6563746976657765622f64622e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/a43c8857cdafa46aa308e04ab403226f2b905fc21e16ab5681ab05716095f809/68747470733a2f2f7472617669732d63692e6f72672f6f626a6563746976657765622f64622e7376673f6272616e63683d6d6173746572)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#db--)

Getting Started
---------------

[](#getting-started)

```
use Objectiveweb\DB;

$db = new DB('pdo uri', 'username', 'password');

// general queries
$db->query('create table ...')->exec();

// insert
$insert_id = $db->insert('table', array('field' => 'value', 'otherfield' => 'value'));

// update (table, values, conditions)
$affected_rows = $db->update('table', array('field' => 'newvalue', ...), array('field' => 'value'));

// select all rows
// returns array ( row1, row2, ...)
$rows = $db->select('table')->all();

// map results by field
// returns associative array { 'row1_field_value' => row1, 'row2_field_value' => row2, ...)
$rows = $db->select('table')->map('field');

// select IN
$rows = $db->select('table', array('ID' => array( 1, 2, 3))->all();

// fetch row by row
$query = $db->select('table');

while($row = $query->fetch()) {
    // process $row
}

// delete (table, conditions)
$db->delete('table', array('field' => 'value'));

// transactions
$db->transaction(function() use ($somevar) {
    $id = $db->insert(...);
    $db->update(...);

    if($condition) {
        throw new \Exception('Error - transaction rolled back');
    } else {
        return $id;
    }
});

```

CRUD Operations
---------------

[](#crud-operations)

```
use Objectiveweb\DB;

$db = new DB(...);

$table = $db->table('tablename', [
    'pk' => 'id',
    'join' => []
]);

// Insert
$id = $table->post(array('field' => 'value', ...);

// Select all rows (returns DB\Collection)
$table->index();

// Get parameters
$data = $table->index([
    'filter' => [ 'field' => 'value' ],
    'sort' => ['id', 'asc'],
    'range' => [ 0, 4 ]
]);

// Number of results
count($data);

// Total number of results (when using range)
$data->total();

foreach($data as $item) {
    $item['field'];
}

// Update (key, values)
$affected_rows = $table->put(array('name' = 'new name'), array('name' => 'old name'));

// Update by ID
$affected_rows = $table->put(id, array('field' => 'new value'));

```

Extending DB\\Table
-------------------

[](#extending-dbtable)

```
class MyTable extends Objectiveweb\DB\Table {
    var $table = 'table_name';
    var $params = [
        'pk => 'id',
        'join' => []
    ];
}

// then, instantiate it
$table = $db->table('MyTable');

$table->post(array('name' => 'new item'));

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance56

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~82 days

Recently: every ~455 days

Total

28

Last Release

1955d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v0.7.0PHP &gt;=5.6.0

### Community

Maintainers

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

---

Top Contributors

[![gbarile](https://avatars.githubusercontent.com/u/53063446?v=4)](https://github.com/gbarile "gbarile (1 commits)")[![GuilhermeBarile](https://avatars.githubusercontent.com/u/502178?v=4)](https://github.com/GuilhermeBarile "GuilhermeBarile (1 commits)")

---

Tags

uisqldb

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

135934.5k1](/packages/danielme85-laravel-log-to-db)[illuminated/db-profiler

Database Profiler for Laravel Web and Console Applications.

168237.4k](/packages/illuminated-db-profiler)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[jasny/persist-sql-query

SQL Query builder and parser

33486.0k4](/packages/jasny-persist-sql-query)[amphp/sql

Asynchronous SQL client for Amp.

201.2M12](/packages/amphp-sql)

PHPackages © 2026

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