PHPackages                             lodev09/php-models - 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. lodev09/php-models

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

lodev09/php-models
==================

A PHP library that allows you to easily create and define your models using PDO.

2.3.6(4y ago)46.1k↓30.1%3[1 issues](https://github.com/lodev09/php-models/issues)1MITPHPPHP &gt;=5.4

Since Sep 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lodev09/php-models)[ Packagist](https://packagist.org/packages/lodev09/php-models)[ Docs](https://github.com/lodev09/php-models)[ RSS](/packages/lodev09-php-models/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (46)Used By (1)

PHP Models
==========

[](#php-models)

A PHP library that allows you to easily create and define your models using PDO

Features
--------

[](#features)

- PDO wrapper
- `FETCH_INTO` made easy
- Model helper

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

[](#installation)

```
$ composer require lodev09/php-models

```

Usage
-----

[](#usage)

### DB.php

[](#dbphp)

The main `\Models\DB` class is a PDO wrapper used to make CRUD much easier. It is a forked code from the [php-pdo-wrapper-class](https://github.com/lonalore/php-pdo-wrapper-class)

```
// connect to your database. Store the $db instance globally -- you only need to connect to your db ONCE!
$db = new \Models\DB(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);
```

Available **CRUD** methods

- `$db->insert($sql, $binds)` or `$db->insert($table, $values)`
- `$db->select($sql, $binds)`
- `$db->row($sql, $binds)` (same with `select` but will return single row)
- `$db->update($sql, $binds)` or `$db->update('table', $values)`
- `$db->delete($sql, $binds)` or `$db->delete('table', $filters)`

The default style is `PDO::FETCH_OBJ`

Example:

```
$users = $db->select("SELECT * FROM users WHERE active = 1 AND username = :username", array('username' => 'lodev09'));
var_dump($users);
```

### Model.php

[](#modelphp)

The `\Models\Model` class is a parent class that can be inherited to a **Model** class. Inheriting this class allows you to automatically map the result "row" into your model class (table). This class basically uses the `PDO::FETC_INTO` style and made it easier for you. Here are the steps to link your table into a class:

1. Initiate the `\Models\DB` instance (see above)

```
$db = new \Models\DB(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);
\Models\Model::setDb($db);
```

2. Create your model class. For example, a `User.php` class

```
namespace Models;

class User extends Model {
    public function getName() {
        return $this->name;
    }
}
```

3. Register your table to your custom class

```
// somewhere in your init.php
\Models\User::register('users');
```

Now, you can directly get the `User` instance from a query. Example:

```
$user = \Models\User::row("SELECT id, name FROM users WHERE id = 1 AND active = 1");
// you can call the getName() method now
if ($user) {
    $name = $user->getName();
    echo 'His name is '.$name;
}
```

Feedback
--------

[](#feedback)

All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at [www.lodev09.com](http://www.lodev09.com "www.lodev09.com") or email me at

Credits
-------

[](#credits)

© 2018 - Coded by Jovanni Lo / [@lodev09](http://twitter.com/lodev09)

License
-------

[](#license)

Released under the [MIT License](http://opensource.org/licenses/MIT). See [LICENSE](LICENSE) file.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

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

Recently: every ~2 days

Total

45

Last Release

1513d ago

Major Versions

1.2.10 → 2.0.02020-11-25

### Community

Maintainers

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

---

Top Contributors

[![lodev09](https://avatars.githubusercontent.com/u/6686328?v=4)](https://github.com/lodev09 "lodev09 (63 commits)")

---

Tags

databasemodelsphp-libraryphp-pdophp-pdo-wrapperphpmysqlpdoclassmodelsmysql-pdopdo-modelsmodels-php

### Embed Badge

![Health badge](/badges/lodev09-php-models/health.svg)

```
[![Health](https://phpackages.com/badges/lodev09-php-models/health.svg)](https://phpackages.com/packages/lodev09-php-models)
```

###  Alternatives

[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M68](/packages/ifsnop-mysqldump-php)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[eftec/pdoone

Minimaist procedural PDO wrapper library

1105.9k9](/packages/eftec-pdoone)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)[riverside/php-orm

PHP ORM micro-library and query builder

111.2k](/packages/riverside-php-orm)

PHPackages © 2026

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