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

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

phore/orm
=========

Object Relational Mapper

v1.2.1(2y ago)1104MITPHPPHP &gt;=8.1

Since Jul 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/phore/phore-orm)[ Packagist](https://packagist.org/packages/phore/orm)[ RSS](/packages/phore-orm/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Phore MiniSql
=============

[](#phore-minisql)

Overview
--------

[](#overview)

Phore MiniSql is a lightweight ORM library for PHP, providing an easy-to-use interface for database operations such as create, read, update, delete (CRUD), and schema management. This README provides detailed usage instructions, including entity definitions, handling operations, indexes, foreign keys, and table/connection maintenance.

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

[](#installation)

To install Phore MiniSql, use Composer:

```
composer require phore/minisql
```

Defining Entities
-----------------

[](#defining-entities)

Entities are defined as PHP classes with public properties representing the columns of the corresponding database table. Each entity class must implement a static `__schema` method that returns an `OrmClassSchema` object.

```
namespace App\Entity;

use Phore\MiniSql\Schema\OrmClassSchema;

class User
{
    public int $id;
    public string $name;
    public string $email;

    public static function __schema(): OrmClassSchema
    {
        return new OrmClassSchema(
            tableName: 'users',
            primaryKey: 'id',
            autoincrement: true,
            columns: [
                'id' => 'int',
                'name' => 'varchar(255)',
                'email' => 'varchar(255)'
            ]
        );
    }
}
```

Usage
-----

[](#usage)

### Connecting to the Database

[](#connecting-to-the-database)

To connect to the database, create an instance of the `Orm` class and provide the DSN and entity classes.

```
use Phore\MiniSql\Orm;
use App\Entity\User;

$orm = new Orm([User::class], 'mysql:host=localhost;dbname=testdb;user=root;password=root');
$orm->connect();
$orm->updateSchema();
```

### Creating Records

[](#creating-records)

To create a new record, instantiate the entity class, set its properties, and call the `create` method.

```
$user = new User();
$user->name = 'John Doe';
$user->email = 'john.doe@example.com';
$orm->create($user);
```

### Reading Records

[](#reading-records)

To read a record by its primary key, use the `read` method.

```
$user = $orm->withClass(User::class)->read(1);
```

### Updating Records

[](#updating-records)

To update a record, modify its properties and call the `update` method.

```
$user->name = 'Jane Doe';
$orm->update($user);
```

### Deleting Records

[](#deleting-records)

To delete a record, call the `delete` method.

```
$orm->delete($user);
```

### Listing All Records

[](#listing-all-records)

To list all records of an entity, use the `listAll` method.

```
$users = $orm->withClass(User::class)->listAll();
```

### Selecting Records with Conditions

[](#selecting-records-with-conditions)

To select records with specific conditions, use the `select` method.

```
$users = $orm->withClass(User::class)->select(['name' => 'Jane Doe']);
```

Indexes
-------

[](#indexes)

Indexes can be defined in the `OrmClassSchema` using the `indexes` property.

```
public static function __schema(): OrmClassSchema
{
    return new OrmClassSchema(
        tableName: 'users',
        primaryKey: 'id',
        autoincrement: true,
        columns: [
            'id' => 'int',
            'name' => 'varchar(255)',
            'email' => 'varchar(255)'
        ],
        indexes: [
            new OrmIndex(
                columns: ['email'],
                type: 'UNIQUE'
            ),
            new OrmIndex(
                columns: ['hit_id', "tag"],
                indexName: 'idx_hit_id_tag',
                type: 'INDEX'
            )
        ],
        foreignKeys: [
            new OrmForeignKey("hit_id", Hit::class, "id", onDelete: "cascade")
        ]
    );
}
```

Foreign Keys
------------

[](#foreign-keys)

Foreign keys can be defined in the `OrmClassSchema` using the `foreignKeys` property.

```
use Phore\MiniSql\Schema\OrmForeignKey;

public static function __schema(): OrmClassSchema
{
    return new OrmClassSchema(
        tableName: 'orders',
        primaryKey: 'id',
        autoincrement: true,
        columns: [
            'id' => 'int',
            'user_id' => 'int',
            'product_id' => 'int'
        ],
        foreignKeys: [
            new OrmForeignKey('user_id', 'users', 'id'),
            new OrmForeignKey('product_id', 'products', 'id')
        ]
    );
}
```

Maintaining Tables and Connections
----------------------------------

[](#maintaining-tables-and-connections)

### Updating Schema

[](#updating-schema)

To update the database schema based on the defined entities, use the `updateSchema` method.

```
$orm->updateSchema();
```

### Dropping All Tables

[](#dropping-all-tables)

To drop all tables in the database, use the `dropAllTables` method.

```
$orm->getDriver()->getSchemaUpdater()->dropAllTables();
```

Conclusion
----------

[](#conclusion)

Phore MiniSql provides a simple and efficient way to manage database operations in PHP. By defining entities and using the provided methods, you can easily perform CRUD operations, manage indexes and foreign keys, and maintain your database schema.

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance54

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 72% 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

768d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/878a384d056698a2400e4b7c8858db05a6caebb2c560e67151be36d46d58def0?d=identicon)[dermatthes](/maintainers/dermatthes)

---

Top Contributors

[![dermatthes](https://avatars.githubusercontent.com/u/13380559?v=4)](https://github.com/dermatthes "dermatthes (18 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (7 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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