PHPackages                             pakanhu/myorm - 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. pakanhu/myorm

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

pakanhu/myorm
=============

A simple PHP ORM for MySQL database

v1.0.0(7y ago)013MITPHPPHP &gt;=5.5

Since Jul 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/paKanhu/MyORM)[ Packagist](https://packagist.org/packages/pakanhu/myorm)[ RSS](/packages/pakanhu-myorm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)DependenciesVersions (2)Used By (0)

pakanhu/myorm
=============

[](#pakanhumyorm)

pakanhu/myorm is a simple and extensible PHP ORM library to work with MySQL database. It has an expressive query builder to read data with multi-table support.

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

[](#installation)

Install with composer `composer require pakanhu/myorm`

Usage
-----

[](#usage)

First, create a "Database" instance. It creates a static database connection, which will be used by "Model" internally.

```
new \paKanhu\MyORM\Database(
    'db_host',
    'db_name',
    'db_username',
    'db_password',
    'db_timeZone'
);
```

Extend your model from "paKanhu\\MyORM\\Model". Database column names should be in snake case and corresponding properties in your class should be in camel case.

```
class Product extends \paKanhu\MyORM\Model
{
    protected $id;          // DB Column Name - id (Primary Key)
    protected $sku;         // DB Column Name - sku
    protected $name;        // DB Column Name - name
    protected $price;       // DB Column Name - price
    protected $categoryId;  // DB Column Name - category_id
    protected $createdAt;   // DB Column Name - created_at

    // Table name is mandatory
    protected static $tableName = 'products';

    // Define if primary key in your table is different than "id"
    // protected static $primaryColumn = 'sku';

    /*
    Define if table contains fractional timestamp.
    This is required for workaround a PHP PDO bug while dealing with
    fractional timestamp in MySQL (TIMESTAMP(>0)).
    If it's defined a new property named 'createdAtFractional' will be
    created having fractional timestamp value.
    */
    // protected static $fractionalTimestamps = ['createdAt'];

    // Define to direct access of property outside of class
    // protected static $guarded = ['categoryId'];
}

// To get product with id 100
$product = Product::getById(100);

// To get product with unique sku SKU-123
$product = Product::getBySku('SKU-123', ['isUnique' => true]);

// To get all products of category id 10
$products = Product::getByCategoryId(10);
// is same as
$products = Product::getAll([
    'where' => [[
        'column' => 'categoryId',   // Property name
        'value' => 10,
        // 'condition' => '!=', // MySQL condition (Default is =)
    ]]
]);

// To get 5 new products of category id 10
$products = Product::getAll([
    'where' => [[
        'column' => 'categoryId',
        'value' => 10,
    ]],
    'orderBy' => [
        'column' => 'createdAt',
        'mode' => 'DESC'
    ],
    'limit' => [
        'rowCount' => 5,
        // 'offset' => 10,  // To set offset (Default is 0)
    ]
]);

// To get all products of category id 10 with category details
$products = Product::getByCategoryId(10, [
    'with' => [[
        'column' => 'categoryId',
        'class' => Category::class,
        'property' => 'category',

        // Required when table is not joined with primary key of other table
        // 'foreignColumn' => 'categoryUniqueId',

        // Required for one-to-many relationship (Default value - true)
        // 'isUnique' => false,

        // Complete 'filters' array can be passed as it's in 'getAll' method
        // 'filters' => [],
    ]]
]);
// echo $products[0]->category->name;

// To get all products of category id 10 with only category name
$products = Product::getByCategoryId(10, [
    'with' => [[
        'column' => 'categoryId',
        'class' => Category::class,
        'property' => 'category',
        'filters' => [
            // If 'select' filter is used, then result will be in array
            'select' => ['name']
        ],
    ]]
]);
// echo $products[0]->category['name'];

// To get all product names
$products = Product::getAll([
    'select' => 'name',
    'onlyValues' => true
]);
// echo $products[0];

// To get all products of category id 10, 11, 12 AND name starts with 'Apple'
$products = Product::getAll([
    'where' => [[
        'column' => 'categoryId',
        'condition' => 'IN'
        'value' => [10, 11, 12],
    ], [
        'column' => 'name',
        'condition' => 'LIKE',
        'value' => 'Apple%',
    ]]
]);

// To get all products of category id 10, 11, 12 OR name starts with 'Apple'
$products = Product::getAll([
    'whereOr' => [[
        'column' => 'categoryId',
        'condition' => 'IN'
        'value' => [10, 11, 12],
    ], [
        'column' => 'name',
        'condition' => 'LIKE',
        'value' => 'Apple%',
    ]]
]);

/*
To get all products of category id 10 and name starts with 'Apple' OR
category id 11 and name starts with 'Google'.
SQL Query Representation: WHERE (category_id = 10 AND name LIKE 'Apple%') OR
(category_id = 11 AND name LIKE 'Google%')
*/
$products = Product::getAll([
    'where' => [
        'operator' => 'OR',
        'operands' => [[
            'operator' => 'AND',
            'operands' => [[
                'column' => 'categoryId',
                'value' => 10
            ], [
                'column' => 'name',
                'condition' => 'LIKE',
                'value' => 'Apple%'
            ]]
        ], [
            'operator' => 'AND',
            'operands' => [[
                'column' => 'categoryId',
                'value' => 11
            ], [
                'column' => 'name',
                'condition' => 'LIKE',
                'value' => 'Google%'
            ]]
        ]]
    ]
]);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Unknown

Total

1

Last Release

2863d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/29d2d8a9774f64632326813d0793465ef87270209bca474c5653fa6fe3576dbd?d=identicon)[paKanhu](/maintainers/paKanhu)

---

Top Contributors

[![paKanhu](https://avatars.githubusercontent.com/u/3684243?v=4)](https://github.com/paKanhu "paKanhu (3 commits)")

### Embed Badge

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

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

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