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

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

piko/db-record
==============

A lightweight Active Record helper built on top of PDO.

v2.2.3(3mo ago)01152LGPL-3.0-or-laterPHPPHP &gt;=8.1.0CI passing

Since Oct 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/piko-framework/db-record)[ Packagist](https://packagist.org/packages/piko/db-record)[ Docs](https://github.com/piko-framework/db-record)[ RSS](/packages/piko-db-record/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (8)Versions (11)Used By (2)

Piko Db Record
==============

[](#piko-db-record)

[![build](https://github.com/piko-framework/db-record/actions/workflows/php.yml/badge.svg)](https://github.com/piko-framework/db-record/actions/workflows/php.yml)[![Coverage Status](https://camo.githubusercontent.com/009bd58207d4e8e204a9c764ee3419c267af78c3a63efb7b0f173ac349fc0ac7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70696b6f2d6672616d65776f726b2f64622d7265636f72642f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/piko-framework/db-record?branch=main)

Piko Db Record is a lightweight Active Record implementation built on top of PDO.

It has been tested and works with the following databases:

- SQLite
- MySQL
- PostgreSQL
- MSSQL

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

[](#installation)

It's recommended that you use Composer to install Piko Db Record.

```
composer require piko/db-record
```

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

[](#documentation)

Usage
-----

[](#usage)

First, ensure you have the necessary autoloading in place:

```
require 'vendor/autoload.php';
```

### Define Your Model

[](#define-your-model)

Use the `Piko\DbRecord`, `Piko\DbRecord\Attribute\Table`, and `Piko\DbRecord\Attribute\Column`classes to define your model. For example:

```
use Piko\DbRecord;
use Piko\DbRecord\Attribute\Table;
use Piko\DbRecord\Attribute\Column;

#[Table(name:'contact')]
class Contact extends DbRecord
{
    #[Column(primaryKey: true)]
    public ?int $id = null;

    #[Column]
    public $name = null;

    #[Column]
    public ?int $order = null;
}
```

### Setup Database Connection

[](#setup-database-connection)

Create a new PDO instance and set up your database schema:

```
// See https://www.php.net/manual/en/class.pdo.php
$db = new PDO('sqlite::memory:');

$query = order = 1;
$contact->save();

echo "Contact id : {$contact->id}"; // Contact id : 1
```

#### Read

[](#read)

Retrieve records from the database:

```
$st = $db->prepare('SELECT * FROM contact');
$st->execute();
$rows = $st->fetchAll(PDO::FETCH_CLASS, Contact::class, [$db]);

print_r($rows); // Array ([0] => Contact Object(...))

// Load a single record by primary key:
$contact = (new Contact($db))->load(1);

var_dump($contact->name); // John
```

#### Delete

[](#delete)

Delete a record from the database:

```
$contact->delete();
print_r($st->fetchAll()); // Array()
```

Support
-------

[](#support)

If you encounter any issues or have questions, feel free to open an issue on GitHub.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance82

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

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

Total

10

Last Release

91d ago

Major Versions

v1.1 → v2.02022-11-04

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

v2.1PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/001b70c85d853a2aae5f1bf74a1ff7ad77ffcec2d423090d67293bde99158350?d=identicon)[ilhooq](/maintainers/ilhooq)

---

Top Contributors

[![ilhooq](https://avatars.githubusercontent.com/u/1500886?v=4)](https://github.com/ilhooq "ilhooq (42 commits)")

---

Tags

databasesqlrecordactive-record

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[catfan/medoo

The lightweight PHP database framework to accelerate development

5.0k1.6M204](/packages/catfan-medoo)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k6.0M77](/packages/ifsnop-mysqldump-php)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6882.2M16](/packages/usmanhalalit-pixie)

PHPackages © 2026

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