PHPackages                             alexsasharegan/model-framework - 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. alexsasharegan/model-framework

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

alexsasharegan/model-framework
==============================

Make getting started with data-driven apps easier by using some solid model classes and database abstractions.

v3.0.0(8y ago)1139MITPHP

Since Nov 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/alexsasharegan/model-framework)[ Packagist](https://packagist.org/packages/alexsasharegan/model-framework)[ RSS](/packages/alexsasharegan-model-framework/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (5)Versions (34)Used By (0)

PHP Model Framework
===================

[](#php-model-framework)

[![Latest Stable Version](https://camo.githubusercontent.com/a8c22ef37029acf2d0c32a355c019a9e821930c325d6e676f5cadc629a3c5c4b/68747470733a2f2f706f7365722e707567782e6f72672f616c65787361736861726567616e2f6d6f64656c2d6672616d65776f726b2f762f737461626c65)](https://packagist.org/packages/alexsasharegan/model-framework)[![Total Downloads](https://camo.githubusercontent.com/b76e8d0017deab24842240de21cf77c79e46b29ec2175b10025e1e0832ada4ae/68747470733a2f2f706f7365722e707567782e6f72672f616c65787361736861726567616e2f6d6f64656c2d6672616d65776f726b2f646f776e6c6f616473)](https://packagist.org/packages/alexsasharegan/model-framework)[![Latest Unstable Version](https://camo.githubusercontent.com/1bed64befbad05b98f2d332fea446391f31c9a17fff56afceaca0236d5df2f5a/68747470733a2f2f706f7365722e707567782e6f72672f616c65787361736861726567616e2f6d6f64656c2d6672616d65776f726b2f762f756e737461626c65)](https://packagist.org/packages/alexsasharegan/model-framework)[![License](https://camo.githubusercontent.com/17c2364107374067d390165f095ff80dc79036cce487c3c12dcb37938e57f31d/68747470733a2f2f706f7365722e707567782e6f72672f616c65787361736861726567616e2f6d6f64656c2d6672616d65776f726b2f6c6963656e7365)](https://packagist.org/packages/alexsasharegan/model-framework)

A lightweight, PDO &amp; MySQL-based data modeling framework in PHP strongly inspired by Laravel &amp; Underscore/Lodash.

Why Another Library
-------------------

[](#why-another-library)

This library has been developed in a production environment to alleviate the difficulties of working with PHP and MySQL.

Developing in the `[LMW]AMP` stack affords the benefits of a high availability of deployment environments. Unfortunately, this also means dealing with the quirks of an inconsistent PHP language API and poor MySQL data type translations to PHP.

This is where the **model-framework** comes in. You can work with models &amp; collections that provide a more consistent API wrapper around PHP, and define casts the work under the hood to enforce the type integrity of the data on your models.

PDO is a great way to interact with MySQL in PHP while simultaneously reducing the potential for injection attacks. This library uses prepared queries under the hood to help you get started with PDO right out of the box. Use simple methods like `Model::removePropsNotInDatabase()` to query your object's table and strip out any fields not defined in your table.

Not familiar with *Object-Oriented PHP*? The model class implements interfaces like **ArrayAccess** and **Traversable** so you can interact with it like a normal associative array, while still getting all the internal data type enforcement.

Getting Started
---------------

[](#getting-started)

Using Composer, load up the library:

```
composer require alexsasharegan/model-framework
```

This library uses the `vlucas/phpdotenv` library to connect models to your database (*already included*). Start by creating a `.env` file with these database connection variables defined:

```
DB_HOST=localhost
DB_DATABASE=sandbox
DB_PORT=3306
DB_CHARSET=utf8
DB_USERNAME=root
DB_PASSWORD=root
```

Now load the environment:

```
