PHPackages                             wepesi/orm - 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. wepesi/orm

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

wepesi/orm
==========

simple orm build for php application

v1.0.0(2y ago)691[2 issues](https://github.com/bim-g/Wepesi-ORM/issues)Apache-2.0PHPPHP ^7.4||^8.0

Since May 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/bim-g/Wepesi-ORM)[ Packagist](https://packagist.org/packages/wepesi/orm)[ RSS](/packages/wepesi-orm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

Wepesi-ORM
==========

[](#wepesi-orm)

Lightweight and simple `Object Relational Mapping` or `ORM`.

OVERVIEW
========

[](#overview)

Only MySQL is supported and developed using `PHP Data Object` or`PDO`,but does not support CLI or Migration. you should have `PDO` extension activated on your php.ini ; Design by using Prepared Statements. Prepared Statements protect from SQL injection, and are very important for web application security.

CONFIGURATION
=============

[](#configuration)

In order to interact with the database, you should provide all required information. To create an instance you should provide database configuration such `host`,`db_name`,`username` and `password`, you can get instance of DB buy call `getInstance` method to get a singleton and take array config as parameters.

```
    use Wepesi\App\DB;
    $config=[
        "host"=>"localhost",
        "db_name"=>"wepesi_db",
        "username"=>"root",
        "password"=>""
    ];
    $db = DB::getInstance($config);
```

Now you have singleton of the database connection.

INTEGRATION
===========

[](#integration)

The Module help as some method build to help

- `select` =&gt; `get`
- `insert` =&gt; `insert`
- `update` =&gt; `update`
- `delete` =&gt; `delete`
- and `transaction`.

- `get` method is corresponding to `SELECT`, it helps to request the database, it as several chained method to help make request more interesting.

```
    use Wepesi\App\DB;
    $config = [
        "host" => "localhost",
        "db_name" => "wepesi_db",
        "username" => "root",
        "password" => ""];
    $db = DB::getInstance($config);
    $req = $db->get('message')->result();
```

- in the `get` method we have the first parameter witch is the `table_name`, then we call the `result()` method to execute your `query` and get result. the corresponding sql is:

```
    SELECT * FROM message;
```

in case you want to select specific field and apply a condition.

```
    $req = $db->get("message")->field(['userid','message'])->where(['userid',"=",1])->result();
    var_dump($req);
```

the corresponding `SQL`

```
    SELECT userid,message FROM message WHERE userid=1
```

- use `field` method to precise what are the field you want to get, all parameters should be passed on a simple array,
- use `where` method to add condition on the request and to use where method there is rule to follow. an array parameter to pass:
    - on the first position is the name of the field name as string,
    - on the second position is operation `'=', '', '!=', 'like'`, this only supported condition for more conditional better to write a \[\*QUERY\](`sql request`).
    - The third position is the value of your condition,
    - and the forth position is for the operator `and`,`or`and `not`, by default it `and`, and it is required whene there is multiple conditiontions.

```
    $where = [
        ['id',"=",2],
        ['username',"like",'admin','or'],
        ['email',"like",'admin']
    ];
    $db->get("message")->field(['fname','lname'])->where($where)->result();
```

```
    SELECT fname,lname FROM message WHERE id=1 AND username like 'admin' or email like 'admin';
```

This is not all, you can `LIMIT`, `OFFSET`,`groupBY`,`orderBy`,`ASC`,`DESC`

```
    $where=[
        ['age',">",20]
    ];
    $db->get("users")->field(['email','address'])->where($where)->orderBy("id")->offset(0)->limit(30)->DESC()->result();
```

### Notes:

[](#notes)

in case there is problem as `error` method can be called to check if there is any error.

```
$result = $db->get("users")->field(['email','address'])->orderBy("id")->offset(0)->limit(30)->DESC()->result();
if($db->error()) print_r($db->error());
```

Sometimes you want to count record instead if listing them, `count` method is part of get with return an object count. use count object to access the value return.

```
    $count_users = $db->count("users")->field(['email','address'])->where($where)->result();
    echo $count_users->count;
//
```

- `insert` is used to record data. the method take table name as parameter, use field method to pass data to be saved. in case your information are correct the `db` instance you can call`lastId` method to get the id of the inserted record.

```
    $data = [
        "userid" => 2,
        "message" => "hello from wepesi",
        "date_created" => Date('Y-m-d H:i:s')
    ];
    try {
            $db->insert("message")->field($data)->result();
            if ($this->db->error()) {
                throw new \Exception($this->db->error());
            }
            var_dump($this->db->lastId());
    } catch (\Exception $ex) {
        echo $ex->getMessage();
    }
```

the corresponding sql look like

```
    INSERT INTO message (`userid`,`message`,`datecreated`) VALUES (?,?,?)
```

- DELETE `delete` when you need to delete a record, this is the module to use. the same way you write where condition on `get` method is supported only for delete. it will return and array `array("delete" => true)` when the operation success.

```
    try {
        $req = $db->delete("message")->where(["id","=",16])->result();
        if ($this->db->error()) {
            throw new \Exception($this->db->error());
        }
        return $req;
    } catch (\Exception $ex) {
        echo $ex->getMessage();
    }
```

corresponding sql:

```
    DELETE `message` WHERE `id`='16'
```

- `update` when you need to update a record, this is the module to use. the same way you write where condition on `delete` method is supported only for delete. call `rowCount` method to get the number of record updated. You should call `field` method to specify witch field to be updated.

```
    try {
        $field = ["text" => "new messages from now"];
        $db->update("message")->field($field)->where(["id","=",16])->result();
        if ($this->db->error()) {
            throw new \Exception($this->db->error());
        }
        return $db->rowCount();
    } catch (\Exception $ex) {
        echo $ex->getMessage();
    }
```

corresponding sql:

```
    update `message`set text=? WHERE `id`='16'
```

- `query` : In case you have complex query,then you can use it.

```
    try{
        $req = $this->db->query("select * from message join users on users.id=message.userid");
        if($req->error()){
            throw new \Exception($req->error());
        }
        return $req->result();
    }catch(\Exception $ex){
        echo $ex->getMessage();
    }
```

the example bellow describe how it can be used. with the `query` method use the `result()` method to get the result.

### Transaction

[](#transaction)

For so many reasons you would like to implement a transaction in case one of your operation failed. Take caution only `InnoDB` support transaction in order to see the result you should be sure your `ENGINE` is innoDB, in case you are not sure about the database engine you can convert your tables only with `convertMyISAMToInnoDB` method. That method will help convert `MyISAM` engine to `InnoDB`. There are two ways to use transaction as been defined. you can manage by your own how, end when to apply transaction or use a builtin `transaction` method. It is recommended to use try catch in or to fulfil the operation.

- #### pdo transaction

    [](#pdo-transaction)

The transaction has tree method to used in order to work properly, we have:

- `beginTransaction` : this method is used to start a transaction, and is shoudl be place at the beginning operation where the transaction will occur.
- `commit` : used this method when the operation succeeds.
- `rollBack` : is used to cancel all the operation.

```
  try{
  $user = [
    "fullname" => "Celestin Doe",
    "username" => "JohnDoe",
    "password" => md5("12345678"),
    "datecreated" => Date("Y-m-d H:i:s",time())
  ];
  $message = [
      "message" => "Hello Celestin",
      'datecreated' => Date('Y-m-d H:i:s', time())
  ];
    $db->beginTransaction();
     $db->insert('users')->field($user)->result();
      if ($db->error()) {
          throw new \Exception($db->error());
      }

      $user_id = $db->lastId();
      $user['id'] = $user_id;
      $message['user_id'] = $user_id;
      $db->insert('message')->field($message)->result();
      if ($db->error()) {
          throw new \Exception($db->error());
      }
      $message['id'] = $db->lastId();

      $user['messages'] = $message;

      print_r($user);
      $db->commit();
  }
  catch(\Exception $ex){
    $db->rollBack();
  }
```

- #### Transaction as callback

    [](#transaction-as-callback)

method support closure method to be passed as parameter.
You don't need to manage every situation of the transaction, the method help you the focus implementation, and it will do the job for you.

```
    $user = [
      "fullname" => "Celestin Doe",
      "username" => "John Doe",
      "password" => md5("12345678"),
      "datecreated" => Date("Y-m-d H:i:s",time())
    ];

  $message = [
    "message" => "Hello Celestin",
    'datecreated' => Date('Y-m-d H:i:s', time())
  ];
  try {
    $db->transaction(function($db) use ($user,$message){
      $db->insert('users')->field($user)->result();
      if ($db->error()) {
        throw new \Exception($db->error());
      }
      $user_id = $db->lastId();
      $user['id'] = $user_id;
      $message['user_id'] = $user_id;
      $db->insert('message')->field($message)->result();
      if ($db->error()) {
        throw new \Exception($db->error());
      }
      $message['id'] = $db->lastId();
      $user['messages'] = $message;
      print_r($user);
    });
  } catch (\Exception $ex) {
    var_dump($ex);
  }
```

- hope you enjoy. The ORM does not have join method or inclusion, on case to do that better to use [\*QUERY](%60query%60) method.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Every ~225 days

Total

3

Last Release

1026d ago

Major Versions

v0.2.beta → v1.0.02023-07-27

PHP version history (2 changes)v0.1betaPHP &gt;=7.4

v1.0.0PHP ^7.4||^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b7536aed6138da14cfe4d2a295017fd44f2997ee86c689e8aa6276080164cfd?d=identicon)[ibmussa](/maintainers/ibmussa)

---

Top Contributors

[![bim-g](https://avatars.githubusercontent.com/u/16068170?v=4)](https://github.com/bim-g "bim-g (85 commits)")

---

Tags

databasemysqlormphpphp-mysqlphp-ormphp-orm-mysqlsql

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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