PHPackages                             mysimpleorm/mysimpleorm - 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. mysimpleorm/mysimpleorm

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

mysimpleorm/mysimpleorm
=======================

Simple, lightweight and effective ORM using MySQLi

2.1.5(7y ago)9654[1 issues](https://github.com/anthonygauthier/MySimpleORM/issues)[1 PRs](https://github.com/anthonygauthier/MySimpleORM/pulls)MITPHPCI passing

Since Feb 8Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/anthonygauthier/MySimpleORM)[ Packagist](https://packagist.org/packages/mysimpleorm/mysimpleorm)[ RSS](/packages/mysimpleorm-mysimpleorm/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (1)Versions (13)Used By (0)

MySimpleORM
===========

[](#mysimpleorm)

MySimpleORM is a simple PHP/MySQL Object-relational mapping library. It is lightweight and tries to take care of as many things as possible. It allows you to focus on coding the business logic of your application without having to think too much about the SQL queries, simply write your conditions and the ORM will take care of the rest 😄 !

Setting up MySimpleORM (MsORM)
------------------------------

[](#setting-up-mysimpleorm-msorm)

To be able to use the ORM, you need to have a PHP application and a MySQL/MariaDB database. Follow these simple guidelines to setup MsORM within your PHP web app.

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

[](#installation)

The recommended method of installation is via [composer](https://getcomposer.org/)

`composer require mysimpleorm/mysimpleorm`

### Database-side guidelines

[](#database-side-guidelines)

1. The name of your tables are going to be the names of your object classes in PHP. Therefore, a table named "Users" will refer to the class "Users".

### Setup

[](#setup)

Add the following to your PHP class:

1. `require 'vendor/autoload.php;`
2. `use MySimpleORM\BaseClass;`
3. `extends BaseClass`
4. Change your `private` class attributes to `protected` to give access to the mapper.
5. Setup your MySQL/MariaDB information (check the example below)

No need for getters/setters, the `BaseClass` provides you a generic methods.

#### Example

[](#example)

```
require 'vendor/autoload.php';

use MySimpleORM\BaseClass;

class MyClass extends BaseClass {
  protected $IDMyClass;
  protected $Name;

  public function MyClass() {
    parent::__construct($this);
    /**
    * There are two ways to connect the ORM to your Database.
    *
    * 1. Set the following environment variables:
    *    - DB_HOSTNAME
    *    - DB_USERNAME
    *    - DB_PASSWORD
    *    - DB_DATABASE
    *    - DB_PORT
    *
    * 2. Call the following method
    *    - $this->Mapper->Database->setup($host, $user, $password, $db, $port);
    */
    $this->IDMyClass = 0;
    $this->Name = "";
  }
  public function __destruct() {}
}
```

#### Example of a table

[](#example-of-a-table)

*MyClass*IDMyClassNameDocumentation
-------------

[](#documentation)

\*The examples below are all used as if they were part of a function within a controller (MVC).

### Generic get/set

[](#generic-getset)

The ORM provides generic get &amp; set methods to help alleviate the content of your class.

#### Get

[](#get)

```
$Users = new Users();
$name = $Users->get('Name');
// $class->get(attribute_name) => returns value of the attribute
```

#### Set

[](#set)

```
$Users = new Users();
$name = $Users->set('Name', 'foo');
// $class->set(attribute_name, value) => sets the attribute to the value
```

### Select

[](#select)

#### To select an object by its ID

[](#to-select-an-object-by-its-id)

```
$Users = new Users();
$Users = $Users->findById(1);
```

You've retrieved the user "1" from the table "Users" and can now use it as an object.

#### To retrieve an array of objects

[](#to-retrieve-an-array-of-objects)

```
$Users = new Users();
//replace by whatever condition you desire
$wheres = array(
    "column" => "IDCompanies",
    "condition" => "=",
    "value" => 1 //keep in mind you could use a sub-query here
);
// OR
$wheres = array(
"IDCompanies,=,1"
)
$Users = $Users->getArray($wheres);
```

You've just retrieved all the users that were part of the company "1". You're object `$Users` is now an array of `Users`

#### To retrieve current object, depending on what you've already set

[](#to-retrieve-current-object-depending-on-what-youve-already-set)

Assuming the database contains a`Users` with the name "foo".

```
$Users = new Users();
$Users->set("Name", "foo");
$Users = $Users->getCurrent();

//The mapper returned the object User named "foo"
```

### Insert / Update / Delete

[](#insert--update--delete)

Inserting, updating or deleting an object is very simple. All you need to do is call a few functions!

```
//Insert & Update
$Users = new $Users();
$Users->set("Name", "foo");
$Users->save(); // inserted

$Users->set("Name", "bar");
$Users->save(); // updated

//Delete
$Users->delete();
// $Users is now undefined
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance55

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity68

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

Recently: every ~1 days

Total

9

Last Release

2646d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21aa70069a36c83cfac70b9072a8cee30caa6c71fdc7565ae06492f6eadda34a?d=identicon)[delirius325](/maintainers/delirius325)

---

Top Contributors

[![anthonygauthier](https://avatars.githubusercontent.com/u/6709533?v=4)](https://github.com/anthonygauthier "anthonygauthier (94 commits)")

---

Tags

cruddatabasedatabase-abstractionjsonlibrarymysqlmysqliobjectobject-detectionobject-mapperobject-mappingobject-orientedobject-relationalobject-relational-mapperormorm-php-frameworkphpphp5php7sqlobject

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198628.3k10](/packages/pgvector-pgvector)

PHPackages © 2026

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