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

ActivePhp-library[Database &amp; ORM](/categories/database)

axisstudios/db-record
=====================

Manage database records. This library is part of the SoloProyectos PHP API.

4.4.2(8y ago)02MITPHPPHP &gt;=5.5.0

Since Oct 9Pushed 3mo agoCompare

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

READMEChangelogDependencies (3)Versions (18)Used By (0)

DbRecord
========

[](#dbrecord)

Introduction
------------

[](#introduction)

`DbRecord` is a library that allows us to operate databases without manually execute SQL statements. Unlike other similar libraries, **DbRecord allows us to operate on multiple tables at the same time**, resulting in a more concise and clear code.

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

[](#installation)

This package is provided via [composer](https://getcomposer.org/) package manager. Just create a `composer.json` file and execute the following command in the same directory:

```
composer install
```

See [Basic Usage](https://getcomposer.org/doc/01-basic-usage.md) for more info.

Database requirements
---------------------

[](#database-requirements)

This library can operate any MySQL database, with the only condition that each table **MUST** have a primary key composed by a single auto-increment column. By default, the primary key is called `ID`, but you can change it from the constructor.

Basic examples: insert(), update(), select() and delete()
---------------------------------------------------------

[](#basic-examples-insert-update-select-and-delete)

We use the `DbRecordTable` class to perform basic operations.

**Inserting records**

To insert records, we ommit the `id` parameter from the constructor:

```
// insert a record, as the 'id' parameter is not present
$t = new DbRecordTable($db, "table0");
$id = $t->insert(["title" => "New title", "created_at" => date("Y-m-d H:i:s")]);
echo "Inserted record ID: $id";
```

**Updating records**

Updates the record ID=1:

```
$t = new DbRecordTable($db, "table0");
$t->update(["title" => "New title", "created_at" => date("Y-m-d H:i:s")], 1);
```

**Inserting/Updating records**

You can insert or update a record in the same line. For example:

```
$t = new DbRecordTable($db, "table0");
// if $recordId is null, insert a new record and returns the id,
// otherwise update the current record
$recordId = $t->save(["title" => "New title", "created_at" => date("Y-m-d H:i:s")], $recordId);
echo $recordId;
```

**Selecting records**

Selects the record ID=1:

```
$t = new DbRecordTable($db, "table0");
list($title, $createdAt) = $t->select(["title", "created_at"], 1);
echo "title: $title, Created at: $createdAt";
```

**Deleting records**

Delete the record ID=1:

```
$t = new DbRecordTable($db, "table0");
$t->delete(1);
```

For a more complex example see [test1.php](test/test1.php).

General example: Accessing several tables at the same time
----------------------------------------------------------

[](#general-example-accessing-several-tables-at-the-same-time)

Let's say that we have a main table (`table0`) and three secondary tables (`table1`, `table2` and `table3`). The three tables are 'left joined' to the main table through the columns `table1_id`, `table2_id` and `table3_id`. That is: [![test](https://cloud.githubusercontent.com/assets/5312427/12149778/ec2fa156-b4a5-11e5-8697-f423856bb3cd.png)](https://cloud.githubusercontent.com/assets/5312427/12149778/ec2fa156-b4a5-11e5-8697-f423856bb3cd.png)

Instead of operating on tables individually, we can do it at the same time. The following example selects a record (ID = 1) and updates or inserts records on `table1`, `table2` and `table3`:

```
// the following example updates table0, table1, table2 and table3 at the same time
$t = new DbRecordTable($db, "table0");
$t->update(
  [
    "title" => "My title",
    "created_at" => date("Y-m-d H:i:s"),
    "table1.title" => "Title 1",
    "table2.title" => "Title 2",
    "table3.title" => "Title 3"
  ],
  1
);
```

The following example selects a record (ID = 1) and retrieves columns from `table0`, `table1`, `table2` and `table3` at the same time:

```
$t = new DbRecordTable($db, "table0");
list($title, $createdAt, $t1Title, $t2Title, $t3Title) = $t->select(
  [
    "title",
    "created_at",
    "table1.title",
    "table2.title",
    "table3.title"
  ],
  1
);
echo "title: $title, created_at: $createdAt, table1.title: $t1Title, table2.title, $t2Title, table3.title, $t3Title";
```

For a more complex example see [test2.php](test/test2.php).

Column path expressions
-----------------------

[](#column-path-expressions)

In the previous examples we accessed the `title` column of `table1` through the following expression: `table1.title`. The general format is as follows:

```
table1[id = table0_id].title

```

We can omit `id` and `table0_id`, as they are taken by default. So the previous expression can by simplified as follows:

```
table1.title

```

Let's imagine a more complex example. Let's say that `table2` depends on `table1` which, at the same time, depends on `table0`. That is:

[![test1](https://cloud.githubusercontent.com/assets/5312427/12151271/924a197e-b4ae-11e5-9ea8-a69b36489e54.png)](https://cloud.githubusercontent.com/assets/5312427/12151271/924a197e-b4ae-11e5-9ea8-a69b36489e54.png)

In that case, we use the following code to access the `table1` and `table2` columns:

```
$t = DbRecordTable($db, "table0");
list($title, $t1Title, $t2Title) = $t->select(
  [
    "title",
    "table1.title",
    "table2[table1.table2_id].title"
  ],
  1
);
```

The previous expressios are simplified versions of the general expressions:

```
table1[id = table1_id].title
table2[id = table1.table2_id].title

```

We can omit `id` and `_id`, as they are taken by default.

For more complex examples see [test3.php](test/test3.php), [test4.php](test/test4.php) y [test5.php](test/test5.php)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance53

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~56 days

Recently: every ~127 days

Total

16

Last Release

3032d ago

Major Versions

1.0.4 → 2.0.02016-01-06

2.0.0 → 3.0.02016-02-07

3.1.0 → 4.0.02016-02-17

### Community

Maintainers

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

---

Top Contributors

[![gchumillas](https://avatars.githubusercontent.com/u/5312427?v=4)](https://github.com/gchumillas "gchumillas (5 commits)")[![eli007s](https://avatars.githubusercontent.com/u/332471?v=4)](https://github.com/eli007s "eli007s (1 commits)")

### Embed Badge

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

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

###  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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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