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

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

bgillet/slim-orm
================

ORM for Slim framework based on Idiorm &amp; Paris.

1.1.0(11y ago)42753[1 issues](https://github.com/bgillet/slim-orm/issues)MITPHP

Since Oct 11Pushed 11y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Slim-Orm
========

[](#slim-orm)

This package contains a wrapper for to [Idiorm &amp; Paris ORM](http://j4mie.github.io/idiormandparis/ "Idiorm & Paris ORM").

Requirements
============

[](#requirements)

This package is compatible with :

- Slim-Utils 1.3 or greater
- Slim 2.4 or greater
- Paris 1.5 or greater

Installation
============

[](#installation)

You have two options :

- Downloading from GitHub

    - You have only one class to include from `src` folder called `BenGee\Slim\Db\SlimORM`
    - Of course, you must previously import `Slim` and `Paris` bootstrap classes to your code before importing this one
- Downloading from Composer

    - Add the `bgillet/slim-orm` package to your `composer.json`
    - Then just include your `vendor/autoload.php` file as usual and its done

Configuration
=============

[](#configuration)

In your Slim configuration, set your connections parameters as follow :

```
$config = array
(
    SlimORM::CONNECTIONS => array
    (
        SlimORM::DEFAULT_CNX => array
        (
            SlimORM::DSN => 'mysql:host=localhost;port=3306;dbname=slim1',
            SlimORM::USR => 'root',
            SlimORM::PWD => '',
            SlimORM::OPT => null
        ),
        'named_connection' => array
        (
            SlimORM::DSN => 'mysql:host=localhost;port=3306;dbname=slim2',
            SlimORM::USR => 'root',
            SlimORM::PWD => '',
            SlimORM::OPT => null
        )
    )
);

```

Here are explanations for each parameter :

- `SlimORM::CONNECTIONS`
    - Array of connections to one or more database
- `SlimORM::DEFAULT_CNX`
    - Shortcut to the name of the configuration array of the default connection used by the ORM when none is specified
- `named_connection`
    - Configuration array for a given named connection
- `SlimORM::DSN`
    - PDO compliant connection string to be used by the ORM to connect to database
- `SlimORM::USR`
    - Login to use to connect to the database
- `SlimORM::PWD`
    - Password to use to connect to the database
- `SlimORM::OPT`
    - Additional connection parameters for PDO driver
- `SlimORM::CACHE`
    - Query caching activation parameter (default: false)
- `SlimORM::CACHE_CLEAN`
    - Query caching automatic cleaning activation parameter (default: false)
- `SlimORM::LOG`
    - Query logging activation parameter (default: false)
- `SlimORM::LOG_FNC`
    - Query logging function parameter. This let you set your own callable function to log your queries. See Idiorm documentation for more details.
- `SlimORM::RES_SET`
    - Connection's results return method parameter. This let you choose how results are returned (array or result set). By default, results are returned as array.
- `SlimORM::ERR_MOD`
    - PDO error mode parameter. Accept one of the PDO error mode constant (default: PDO::ERRMODE\_EXCEPTION).
- `SlimORM::QOT_CAR`
    - Identifier quote character parameter. Detected automatically by default.
- `SlimORM::ID_COL`
    - Default ID column name parameter. Let you define name of primary key used by the ORM for every table (default : 'id').
- `SlimORM::ID_OVR`
    - Let you configure name of primary key for a set of tables as an array with table name as key and primary key name as value. By default, this parameter is not specified and the default 'id\_column' parameter value is used.
- `SlimORM::LIM_STY`
    - Let you define limit clause style (TOP or LIMIT) for your connection. By default, this parameter is not specified and the clause style is detected.

All these constants correspond to parameters available in Idiorm or Paris. If there is one or more missing, you still may use the `SlimORM::configure()` static method detailed further. This is a shortcut to the Idiorm's `configure()` method. For more details about available parameters, please consult Idiorm's documentation at  or Paris' documentation at .

How to use
==========

[](#how-to-use)

Let's have a look to the sample code below :

```
SlimORM test page
