PHPackages                             clagiordano/weblibs-dbabstraction - 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. clagiordano/weblibs-dbabstraction

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

clagiordano/weblibs-dbabstraction
=================================

Abstraction library for the database and ORM modules

v1.0.8(9y ago)0732LGPL-3.0PHPPHP &gt;=5.4

Since Jan 18Pushed 9y agoCompare

[ Source](https://github.com/clagiordano/weblibs-dbabstraction)[ Packagist](https://packagist.org/packages/clagiordano/weblibs-dbabstraction)[ Docs](https://github.com/clagiordano/weblibs-dbabstraction.git)[ RSS](/packages/clagiordano-weblibs-dbabstraction/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (22)Used By (2)

[![BuildStatus](https://camo.githubusercontent.com/6227ea1ae1f9b1030941cb019d80153eb26738a4befc6f58b123bbce892ecda8/68747470733a2f2f7472617669732d63692e6f72672f636c6167696f7264616e6f2f7765626c6962732d64626162737472616374696f6e2e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/6227ea1ae1f9b1030941cb019d80153eb26738a4befc6f58b123bbce892ecda8/68747470733a2f2f7472617669732d63692e6f72672f636c6167696f7264616e6f2f7765626c6962732d64626162737472616374696f6e2e7376673f6272616e63683d6d6173746572) [![License](https://camo.githubusercontent.com/7fcccf982f22261af8c62c8ab3dfc115e96e985e4fb23a794da3fc5614bfbfae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636c6167696f7264616e6f2f7765626c6962732d64626162737472616374696f6e2e737667)](https://camo.githubusercontent.com/7fcccf982f22261af8c62c8ab3dfc115e96e985e4fb23a794da3fc5614bfbfae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636c6167696f7264616e6f2f7765626c6962732d64626162737472616374696f6e2e737667)

weblibs-dbabstraction
=====================

[](#weblibs-dbabstraction)

weblibs-dbabstraction is an simple and lightweight Abstraction library for the database and ORM modules.

[![SensioLabsInsight](https://camo.githubusercontent.com/cdb086ef08fda2ae9ec7923aa141bb5de17c0fe3ffd5923cd9402fd7e0d2ae90/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62613864623862392d316166372d343731622d393635652d6430353566323362366463652f6269672e706e67)](https://insight.sensiolabs.com/projects/ba8db8b9-1af7-471b-965e-d055f23b6dce)

Why use weblibs-dbabstraction ?
-------------------------------

[](#why-use-weblibs-dbabstraction-)

The purpose of this project is to propose a simple and lightweight alternative solution instead of more big and complex projects such as Doctrine.

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

[](#installation)

The recommended way to install weblibs-dbabstraction is through [Composer](https://getcomposer.org).

```
composer require clagiordano/weblibs-dbabstraction
```

Description of the main components
----------------------------------

[](#description-of-the-main-components)

### Adapter description

[](#adapter-description)

Is a persistence layer which interact with database or other backends. An adapter class must be implements the **DatabaseAdapterInterface** for compatibility with other components.
The default adapter is the already defined **PDOAdapter** wich simplify the access to PDO object and related methods.
Other specific adapters can be implemented to easily access to other backends.

### Adapter usage

[](#adapter-usage)

```
new PDOAdapter(
    $dbHost,
    $dbUser,
    $dbPassword,
    $dbName,
    $dbDriver,
    $dbCharset,
    $isPersistent
);
```

See PDOAdapterTest class (phpunit test class) for full sample usage into tests folder.

### Entity description

[](#entity-description)

An *entity* is an object which expose properties dynamically generated from an array of fields. It is a simple class which have defined the magic methods (\_\_set, \_\_get ... ).
The entity is automatically used by the *mapper* class for the operations and can be used to gets and sets its properties.
*For more details please see the SampleEntity class into testdata folder.*

### Entity usage

[](#entity-usage)

An entity class must be extends **AbstractEntity** as:

```
/**
 * Class SampleEntity
 */
class SampleEntity extends AbstractEntity
{
}
```

Then can be used:

```
$entityClass->property = "value";
echo $entityClass->property;
```

### Mapper description

[](#mapper-description)

A mapper is a glue between **Entity** and **Adapter** objects which expose high level method to use and persists data.
A mapper class must be extends the **AbstractMapper**:

```
/**
 * Class SampleMapper
 */
class SampleMapper extends AbstractMapper
{
```

then must be declare two protected properties to connect database table for persistence and the related entity class:

```
protected $entityTable = 'sample_table';
protected $entityClass = 'SampleEntity';
```

therefore must be implements the abstract method **createEntity** for the correct mapping between table fields and the desidered entity properties:

```
protected function createEntity(array $fields)
{
    return new SampleEntity(
        [
            'id' => $fields['id'],
            'code' => $fields['code'],
            'brand' => $fields['brand'],
            'model' => $fields['model'],
            'description' => $fields['description']
        ]
    );
}
```

You can also define additional methods if necessary or override existing ones such as insert, update, delete etc to modify its behavior.

### Mapper usage

[](#mapper-usage)

To improve control and security AbstractMapper's methods can be overrided:

```
/**
 * Sample overrided insert method
 *
 * @param SampleEntity $entity
 * @return mixed
 */
public function insert($entity)
{
    if (!$entity instanceof SampleEntity) {
        throw new \InvalidArgumentException(
            __METHOD__ . ": Invalid entity type."
        );
    }

    return $this->adapter->insert($this->entityTable, $entity->toArray());
}
```

As you can see, this overrided method require explicitly an instance of SampleEntity to works, the same way you can run a validation or additional arguments formatting/sanitizing or whatever you want.

Legal
-----

[](#legal)

*Copyright (C) Claudio Giordano *

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

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

Recently: every ~27 days

Total

20

Last Release

3597d ago

Major Versions

v0.9 → v1.0.02016-03-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8440925?v=4)[Claudio Giordano](/maintainers/clagiordano)[@clagiordano](https://github.com/clagiordano)

---

Top Contributors

[![clagiordano](https://avatars.githubusercontent.com/u/8440925?v=4)](https://github.com/clagiordano "clagiordano (110 commits)")

---

Tags

backenddatabaseentitylibrarymappermysqlormorm-modulespdopdo-wrapperabstractiondatabaselibraryormmysqlpdoentityclagiordanoweblibs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clagiordano-weblibs-dbabstraction/health.svg)

```
[![Health](https://phpackages.com/badges/clagiordano-weblibs-dbabstraction/health.svg)](https://phpackages.com/packages/clagiordano-weblibs-dbabstraction)
```

###  Alternatives

[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

826.0k](/packages/tommyknocker-pdo-database-class)[andsalves/doctrine-elastic

Elasticsearch Doctrine Adaptation

156.6k](/packages/andsalves-doctrine-elastic)[riverside/php-orm

PHP ORM micro-library and query builder

111.3k](/packages/riverside-php-orm)

PHPackages © 2026

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