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

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

danielefavi/slim-orm
====================

Lightweight ORM with an API interface similar to Laravel's ORM Eloquent.

1.1.0(3y ago)263↓100%MITPHP

Since May 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/danielefavi/slim-orm)[ Packagist](https://packagist.org/packages/danielefavi/slim-orm)[ RSS](/packages/danielefavi-slim-orm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

Slim ORM - A lightweight ORM
============================

[](#slim-orm---a-lightweight-orm)

Slim ORM is a lightweight PHP ORM with an API interface similar to the Laravel's ORM (Eloquent).

Please note this ORM has very basic query functionalities; for example it does not support relationships (like `belongsToMany` or `belogsTo`).
Please check some examples below.

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

[](#installation)

Installation via composer
-------------------------

[](#installation-via-composer)

```
composer require danielefavi/slim-orm
```

Setup
-----

[](#setup)

Setting up the DB object with **MySQL**:

```
   $config = [
       'connection' => 'mysql',
       'name' => 'database-name',
       'username' => 'root',
       'password' => 'your_password',
       'options' => [
           \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
       ],
   ];

   $pdo = new \PDO(
       'mysql:host=' . $config['connection'] . ';dbname=' . $config['name'],
       $config['username'],
       $config['password'],
       $config['options']
   );

   $db = DB::init($pdo);
```

Setting up the DB object with **SQLite**:

```
   $pdo = new \PDO('sqlite:' . __DIR__ . '/sqlite.db');

   $db = DB::init($pdo);
```

Usage
-----

[](#usage)

### Query Examples

[](#query-examples)

#### Simple query example

[](#simple-query-example)

```
$res = DB::table('users')
   ->where('name', 'Piripoppi')
   ->orWhere('age', '>=', 30)
   ->get();
```

#### Pagination

[](#pagination)

Return the paginated result (10 items per page).

```
$res = DB::table('users')
   ->orWhere('age', '>=', 30)
   ->paginate(10);
```

#### Full Query example

[](#full-query-example)

```
$res = DB::table('users')
   ->join('comments', '`users`.`id`', '=', '`comments`.`user_id`');
   ->where('id', '>', 30)
   ->where('id', '=', 10)
         ->orWhere('age', '
