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

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

jetfirephp/db
=============

JetFire - Database Abstract Layer

2151PHP

Since Mar 26Pushed 7y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

JetFire Database Abstract Layer for ORM
---------------------------------------

[](#jetfire-database-abstract-layer-for-orm)

A unique facade for orm. For the moment only Doctrine is supported but other orm like RedBean will be supported.

### Installation

[](#installation)

Via [composer](https://getcomposer.org)

```
$ composer require jetfirephp/db
```

For Doctrine usage you have to require the doctrine package

```
$ composer require doctrine/orm
```

For RedBean usage you have to require the redbean package

```
$ composer require gabordemooij/redbean
```

### Quick Start

[](#quick-start)

```
 // Require composer autoloader
 require __DIR__ . '/vendor/autoload.php';

 // database config
 $options = [
     'driver' => 'mysql',
     'host' => 'localhost',
     'user' => 'root',
     'pass' => '',
     'db' => 'project',
     'prefix' => 'jt_',
     'path' => [__DIR__.'/']
 ];

 // Model facade
 $db = new \JetFire\Db\Doctrine\DoctrineModel($options);
 JetFire\Db\Model::init($db);

 // or for lazy loading
 // $db = [
 //     'doctrine' => function() use ($options) {
 //         new \JetFire\Db\Doctrine\DoctrineModel($options);
 //     }
 // ]
 // JetFire\Db\Model::provide($db);

 // And for retrieve data you have 2 possible ways

 // 1)
 $accounts = Model::table('Account')->all();

 // 2)
 $accounts = Account::all();
 // Account.php must extends Model class

```

### Support Multiple ORM

[](#support-multiple-orm)

```
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

// configuration
$config = [
    'default' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'user' => 'root',
        'pass' => '',
        'db' => 'project',
        'prefix' => 'jt_',
        'path' => [__DIR__.'/']
    ]
];

// set your orm provider
$providers = [
    'doctrine' => function()use($config){
        return new \JetFire\Db\Doctrine\DoctrineModel($config);
    },
    'redbean' => function()use($config){
        return new \JetFire\Db\RedBean\RedBeanModel($config);
    },
    'pdo' => function()use($config){
        return new \JetFire\Db\Pdo\PdoModel($config);
    },
];

// pass the default orm in second argument or it will take the first given orm in providers
JetFire\Db\Model::provide($providers,['orm'=>'pdo']);

$account1 = Account::orm('doctrine')->select('lastName')->where('firstName','Peter')->get();
$account2 = Account::orm('pdo')->select('lastName')->where('firstName','Peter')->get();
$account3 = Account::orm('redbean')->select('firstName','lastName')->where('firstName','Peter')->orWhere('age','>',20)->get();

// you can also omit the orm method. The model will load the first orm provided (here doctrine). To load another orm by default you have to add the orm key in second argument of provide method
$account3 = Account::select('firstName','lastName')->where('firstName','Peter')->orWhere('age','>',20)->get(); // will load doctrine orm
```

### Support Multiple Databases

[](#support-multiple-databases)

```
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

// configuration
$config = [
    'db1' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'user' => 'root',
        'pass' => '',
        'db' => 'project1',
        'prefix' => 'jt1_',
        'path' => [__DIR__.'/']
    ],
    'db2' => [
        'driver' => 'mysql',
        'host' => 'localhost',
        'user' => 'root',
        'pass' => '',
        'db' => 'project2',
        'prefix' => 'jt2_',
        'path' => [__DIR__.'/']
    ]
];

// set your orm provider
$providers = [
    'doctrine' => function()use($config){
        return new \JetFire\Db\Doctrine\DoctrineModel($config);
    },
    'redbean' => function()use($config){
        return new \JetFire\Db\RedBean\RedBeanModel($config);
    },
    'pdo' => function()use($config){
        return new \JetFire\Db\Pdo\PdoModel($config);
    },
];
JetFire\Db\Model::provide($providers,['orm' => 'pdo', 'db' => 'default']);

$account = Account::orm('doctrine')->db('db1')->all();
```

### Usage

[](#usage)

Let's take an Account table for our example (this is a doctrine table example but it will work with other orms)

```
/**
 * Class Account
 * @Entity
 * @Table(name="accounts")
 */
class Account extends Model{

    /**
     * @Id
     * @Column(type="integer")
     * @GeneratedValue
     */
    protected $id;
    /**
     * @Column(type="string",name="first_name",length=32)
     */
    protected $first_name;
    /**
     * @Column(type="string",name="last_name",length=32)
     */
    protected $last_name;
    /**
     * @Column(type="string",unique=true)
     */
    protected $email;

    /**
     * @return mixed
     */
    public function getFirstName()
    {
        return $this->first_name;
    }

    /**
     * @param mixed $firstName
     */
    public function setFirstName($firstName)
    {
        $this->first_name = $firstName;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getLastName()
    {
        return $this->last_name;
    }

    /**
     * @param mixed $lastName
     */
    public function setLastName($lastName)
    {
        $this->last_name = $lastName;
    }

    /**
     * @return mixed
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param mixed $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }
}
```

#### CRUD

[](#crud)

CRUD stands for Create, Read, Update and Delete. CRUD operations are the core of many web applications.

##### Create

[](#create)

To create a new record in the database from a model, you have 2 ways to do it :

1.

```
Account::create([
    'first_name' => 'Peter',
    'last_name' => 'Parker',
    'email' => 'peter.parker@spiderman.com'
]); // return true or false
// Account::create()->with([...]) will also work
```

2.

```
$account = Account::get(); // return a new account object
$account->first_name = 'Peter'; // you can also use $account->setFirstName('Parker') or $account['first_name'] = 'Parker';
$account->last_name = 'Parker';
$account->email = 'peter.parker@spiderman.com';
$account->save();
```

##### Retrieve &amp; Read

[](#retrieve--read)

To load all accounts :

```
$accounts = Account::all();
```

To load an account, simply pass the ID of the table you're looking for :

```
$account = Account::find(1);
```

If you have to specify other parameters, you can do it like this :

```
// with additional parameters
$account = Account::where('id',1)->where('last_name','Parker')->get();
// or
$account = Account::whereRaw('a.id = :id AND a.last_name = :last_name',['id' => 1, 'last_name' => 'Parker'])->get();
// select only some fields
$account = Account::select('id','first_name')->where('id',1)->where('last_name','Parker')->get(); // return only id and first_name
// order by
$account = Account::orderBy('id','DESC')->get();
// count
$account = Account::where('last_name','Parker')->count(); // return 1
// limit row
$account = Account::take(2); // return only the first 2 accounts
$account = Account::take(2,3); // return the 2 accounts after 3 rows
```

And to read the model data :

```
$first_name = $account->first_name; // return 'Peter'
// or
$first_name = $account->getFirstName(); // return 'Peter'
// or
$first_name = $account['first_name']; // return 'Peter'
```

##### Update

[](#update)

To update a model in the database, you can do it in 3 different ways :

1. Update via ID

```
Account::update(1)->with([
     'first_name' => 'Peter 2',
]);
```

2. Update with conditions

```
Account::where('id',1)->where('id',2)->set(['first_name' => 'Peter 2']);
```

3. Retrieve the table object first then set your fields after

```
$account = Account::where('id',1)->get();
$account->first_name = 'Peter 2'; // you can also use $account->setFirstName('Parker') or $account['first_name'] = 'Parker';
$account->save();
```

##### Delete

[](#delete)

```
Account::destroy(1) // Deleting An Existing Model By Key
Account::destroy(1,2) // multiple key supported
// or
Account::where('id',1)->delete()
// or
$account = Account::find(1);
$account->delete();
```

### Native sql

[](#native-sql)

```
$account = Account::sql('select * form accounts where id = 1');
$account = Account::sql('select * form accounts where id = :id',['id' => 1]); // with parameters
$account = Account::sql('update accounts set last_name = :last_name where id = :id',['last_name' => 'Parker 2','id' => 1]);
```

### Repository

[](#repository)

You can create a repository for your table to handle custom query. Your repository class name must finish with 'Repository'

```
class AccountRepository {

    public function loadParker(){
        return Account::where('last_name','Parker')->get();
    }
}

// you have to add your repository path in your configuration
$config = [
     // previous config
     // ...
     'repositories' => [
        ['path' => 'repository_folder_path','namespace' => 'respository_namespace']
     ],
];

$account = Account::repo()->loadParker();
```

### License

[](#license)

The JetFire Db is released under the MIT public license : .

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

### Community

Maintainers

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

---

Top Contributors

[![mewgan](https://avatars.githubusercontent.com/u/17544034?v=4)](https://github.com/mewgan "mewgan (8 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

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

8441.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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