PHPackages                             flightphp/active-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. flightphp/active-record

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

flightphp/active-record
=======================

Micro Active Record library in PHP, support chain calls, events, and relations.

v0.7.1(1mo ago)164.0k↓31%7[1 issues](https://github.com/flightphp/active-record/issues)11MITPHPPHP &gt;=7.4

Since Jan 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/flightphp/active-record)[ Packagist](https://packagist.org/packages/flightphp/active-record)[ Docs](https://docs.flightphp.com)[ RSS](/packages/flightphp-active-record/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (8)Versions (31)Used By (11)

FlightPHP Active Record
=======================

[](#flightphp-active-record)

[![Latest Stable Version](https://camo.githubusercontent.com/ec7ea76d49336ba80616faeb336029a4c2a720b12448f3ed9a527cfa09a6e8dc/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f6163746976652d7265636f72642f76)](https://packagist.org/packages/flightphp/active-record)[![License](https://camo.githubusercontent.com/1365b833d279acc2a6f6c935191588f70e2b3ec2698369495e42af11b65ec111/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f6163746976652d7265636f72642f6c6963656e7365)](https://packagist.org/packages/flightphp/active-record)[![PHP Version Require](https://camo.githubusercontent.com/971c269f86ef40489f2f0962d3677b7d6fd1259c18504020c5a8380f745a6653/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f6163746976652d7265636f72642f726571756972652f706870)](https://packagist.org/packages/flightphp/active-record)[![Dependencies](https://camo.githubusercontent.com/800ebf15772080b8fe35a46a20913731d7e7f0895db8318c88a2baf2dfe14f86/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f6163746976652d7265636f72642f646570656e64656e7473)](https://packagist.org/packages/flightphp/active-record)

An active record is mapping a database entity to a PHP object. Spoken plainly, if you have a users table in your database, you can "translate" a row in that table to a `User` class and a `$user` object in your codebase. See [basic example](#basic-example).

Basic Example
-------------

[](#basic-example)

Let's assume you have the following table:

```
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  name TEXT,
  password TEXT
);
```

Now you can setup a new class to represent this table:

```
/**
 * An ActiveRecord class is usually singular
 *
 * It's highly recommended to add the properties of the table as comments here
 *
 * @property int    $id
 * @property string $name
 * @property string $password
 */
class User extends flight\ActiveRecord {
  public function __construct($databaseConnection)
  {
    parent::__construct($databaseConnection, 'users', [/* custom values */]);
  }
}
```

Now watch the magic happen!

```
// for sqlite
$database_connection = new PDO('sqlite:test.db'); // this is just for example, you'd probably use a real database connection

// for mysql
$database_connection = new PDO('mysql:host=localhost;dbname=test_db&charset=utf8bm4', 'username', 'password');

// or mysqli
$database_connection = new mysqli('localhost', 'username', 'password', 'test_db');
// or mysqli with non-object based creation
$database_connection = mysqli_connect('localhost', 'username', 'password', 'test_db');

$user = new User($database_connection);
$user->name = 'Bobby Tables';
$user->password = password_hash('some cool password');
$user->insert();
// or $user->save();

echo $user->id; // 1

$user->name = 'Joseph Mamma';
$user->password = password_hash('some cool password again!!!');
$user->insert();

echo $user->id; // 2
```

And it was just that easy to add a new user! Now that there is a user row in the database, how do you pull it out?

```
$user->find(1); // find id = 1 in the database and return it.
echo $user->name; // 'Bobby Tables'
```

And what if you want to find all the users?

```
$users = $user->findAll();
```

What about with a certain condition?

```
$users = $user->like('name', '%mamma%')->findAll();
```

See how much fun this is? Let's install it and get started!

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

[](#installation)

Simply install with Composer

```
composer require flightphp/active-record
```

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

[](#documentation)

Head over to the [documentation page](https://docs.flightphp.com/awesome-plugins/active-record) to learn more about usage and how cool this thing is! :)

License
-------

[](#license)

MIT

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~86 days

Total

28

Last Release

55d ago

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

v0.2.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2322095?v=4)[n0nag0n](/maintainers/n0nag0n)[@n0nag0n](https://github.com/n0nag0n)

---

Top Contributors

[![n0nag0n](https://avatars.githubusercontent.com/u/2322095?v=4)](https://github.com/n0nag0n "n0nag0n (76 commits)")[![lloydzhou](https://avatars.githubusercontent.com/u/1826685?v=4)](https://github.com/lloydzhou "lloydzhou (69 commits)")[![enlivenapp](https://avatars.githubusercontent.com/u/3036663?v=4)](https://github.com/enlivenapp "enlivenapp (3 commits)")[![victorruan](https://avatars.githubusercontent.com/u/6701576?v=4)](https://github.com/victorruan "victorruan (3 commits)")[![Shangshj](https://avatars.githubusercontent.com/u/4253787?v=4)](https://github.com/Shangshj "Shangshj (2 commits)")[![fadrian06](https://avatars.githubusercontent.com/u/109766973?v=4)](https://github.com/fadrian06 "fadrian06 (1 commits)")[![Billtec](https://avatars.githubusercontent.com/u/13103365?v=4)](https://github.com/Billtec "Billtec (1 commits)")

---

Tags

active-recorddatabaseflightphpflipping-sweetmappermysqlormquery-buildersqlitemicrodatabaseormpdoSimpleactive-recordliterelation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/flightphp-active-record/health.svg)

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

###  Alternatives

[bephp/activerecord

micro activerecord library in PHP(only 400 lines with comments), support chain calls and relations(HAS\_ONE, HAS\_MANY, BELONGS\_TO).

1202.1k2](/packages/bephp-activerecord)

PHPackages © 2026

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