PHPackages                             sbronsted/libdatabase - 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. sbronsted/libdatabase

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

sbronsted/libdatabase
=====================

General ORM mapper based on PDO

v2.3.0(5y ago)02731MITPHPPHP &gt;=7.1CI failing

Since Sep 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/sorenbronsted/libdatabase)[ Packagist](https://packagist.org/packages/sbronsted/libdatabase)[ Docs](https://github.com/sorenbronsted/libdatabase)[ RSS](/packages/sbronsted-libdatabase/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (5)Versions (10)Used By (1)

\#Libdatabase

This is a simple ORM database mapper which delivers some convenience methods to query, create and update objects. It does not support associations. Instead I use the convention that a foreign key is the name of the table appended '\_uid'. The only other convention is that an object must have a property named 'uid' and when you call save and the uid == 0 it will be converted to an insert statement otherwise it will be converted to an update statement.

This library uses php PDO library.

Example
-------

[](#example)

Below is defined a Sample class

```
class Sample extends DbObject {

  // Each object must describe the properties of the table
  private static $properties = [
    'uid'            => Property::INT,
    'case_number'    => Property::CASE_NUMBER,
    'date_value'     => Property::DATE,
    'datetime_value' => Property::TIMESTAMP,
    'cpr'            => Property::CPR,
    'int_value'      => Property::INT,
    'string_value'   => Property::STRING,
    'decimal_value'  => Property::DECIMAL,
    'boolean_value'  => Property::BOOLEAN
  ];

  // A transient value which is not persisted
  public $transient_value;

  // mandatory method used by DbObject
  public function getProperties() : array {
    return self::$properties;
  }
}

```

This class will have a corresponding table name sample where properties are columns.

As you se the properties are describe by types, which means that when the object is loaded from a table row, the columns are converted to the property type. In that way the date is not a string, but an date object with meaningful operation.

To create an object and persist it

```
$sample = new Sample();
$uid = $sample->save();

```

To to find one or more objects

```
// returns a single object
$sample = Sample::getByUid($uid);

// returns 0 or more objects
$samples = Sample::getBy(['int_value' => 1]);

```

To change a property and persist it

```
$sample = Sample::getByUid($uid);
$sample->int_value = 1;
$sample->save();

```

To delete an object

```
$sample = Sample::getByUid($uid);
$sample->destroy();

```

You also have access to the lower level database function in the DB class, which provides transformations for DbObject to sql or you can write the sql your self.

Configuration
-------------

[](#configuration)

This library uses the Config class from [libutil](https://github.com/sorenbronsted/libutil), where you can put in the database configuration into the ini file:

```
[defaultDb]
driver=mysql
host=localhost
port=3306
name=yourDatabase
user=yourUserName
password=yourUserPassword
charset=utf8

```

The section name corresponds to the static property $db in the DbObject class. The default name is 'defaultDb'.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

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

Recently: every ~61 days

Total

9

Last Release

2064d ago

Major Versions

v1.1 → v2.02020-01-22

### Community

Maintainers

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

---

Top Contributors

[![segadora](https://avatars.githubusercontent.com/u/6637534?v=4)](https://github.com/segadora "segadora (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sbronsted-libdatabase/health.svg)

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

###  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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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