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

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

losthost/db
===========

Database access with so called DB Objects (descendants of class DBObject)

v2.0.1(2y ago)029612MITPHPPHP ^8.1.1

Since Jul 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Datahider/DB)[ Packagist](https://packagist.org/packages/losthost/db)[ Docs](https://github.com/datahider/DB)[ RSS](/packages/losthost-db/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (1)Versions (46)Used By (12)

About DB
========

[](#about-db)

Database access with so called DB Objects (descendants of class DBObject) that mirror data table structure to your project

DB - making DB connection
-------------------------

[](#db---making-db-connection)

There is an example class DBChildObjectExample that is a descendant of DBObject. Before using DBObject descendant you have to open DB connection with and make some stuff:

```
    DB::connect($db_host, $db_user, $db_pass, $db_name, $db_prefix='', $db_encoding='utf8mb4');
    DB::setClassNamespace("\\your\\namespace\\");   /* use \\ at the begining and the end of namespace */
    DB::checkDataStructure("yourClassOne, yourClassTwo, andSoOn", true);

```

After that you can access a table with your DBObject descendant.

DBObject - accessing data
-------------------------

[](#dbobject---accessing-data)

Some useful operations:

```
    // Creating record:

    $new = new DBChildObjectExample();
    $new->name = "test";
    $new->description = "A test record";
    $new->write();
    $new_record_id = $new->id;

    // Accessing record:

    $existing = new DBChildObjectExample("id = ?", $new_record_id);

    if ($existing->isNew()) {

        throw new \Exception('Object not found');

    } else {
        // Modify object:

        $existing->description = 'New description';
        $existing->write();
    }

```

Special stuff
-------------

[](#special-stuff)

If you need some special processing (like checking or filling data) you may override DBObject::fetch(...) and DBObject::write() methods.

TODO
----

[](#todo)

- добавить параметр формата к DBObject-&gt;asString();

Using with AI
-------------

[](#using-with-ai)

PROMPT.md contains the description of the lib for AI-agents. Copy its content to agent's prompt and ask it to help you in developing your app.

Epilogue
--------

[](#epilogue)

That's it. Have fun.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance59

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

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

Recently: every ~36 days

Total

43

Last Release

56d ago

Major Versions

v1.6.2 → v2.0.02023-10-10

v2.0.1 → v3.0.0-alpha2023-11-16

PHP version history (3 changes)v1.0.0PHP &gt;=7.4.0

v1.5.0PHP &gt;=8.2.10

v2.0.1PHP ^8.1.1

### Community

Maintainers

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

---

Top Contributors

[![Datahider](https://avatars.githubusercontent.com/u/29582937?v=4)](https://github.com/Datahider "Datahider (49 commits)")

---

Tags

databasedb

### Embed Badge

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

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

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k47.9M442](/packages/robmorgan-phinx)[spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

8443.1M60](/packages/spatie-laravel-translation-loader)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

923530.0k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

920281.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

920249.3k8](/packages/fpdo-fluentpdo)

PHPackages © 2026

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