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

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

otter/orm
=========

Simple ORM for SQL Server

01PHP

Since Mar 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phGac/SimpleORM)[ Packagist](https://packagist.org/packages/otter/orm)[ RSS](/packages/otter-orm/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

SimpleORM
=========

[](#simpleorm)

This is a simple ORM with PHP for SQL Server without dependencies.

- [installation](#Installation)
    - [requeriments](#Requeriments)
- [How to Use](#How-to-Use)
    - [SELECT](#SELECT)
    - [CREATE](#CREATE)
    - [UPDATE](#UPDATE)
    - [DELETE](#DELETE)
- [Relationships](#Relationships)
    - [Belongs To](#Belongs-To)
    - [Belongs To Many](#Belongs-To-Many)
    - [Has One](#Has-One)
    - [Has Many](#Has-Many)
- [Libre Query](#Libre-Query)

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

[](#installation)

...

### Requeriments

[](#requeriments)

RequerimentVersionInfoPHP7.0^-PDO\_SQLSRV4.0^It depends on the PHP version[download and configure PDO\_SQLSRV](https://docs.microsoft.com/en-us/sql/connect/php/example-application-pdo-sqlsrv-driver "download and configure PDO_SQLSRV")

How to Use
----------

[](#how-to-use)

```
$orm = new \Otter\ORM\Otter('localhost', 'databaseName', 'sa', 'password');
$orm->schemas(__DIR__.'/schemas');

$User = \Otter\ORM\Otter::get('User');

$users = $User->findAll()
              ->end();

if($users !== null) {
    print_r($users); // array of objects
} else {
    $info = \Otter\ORM\Otter::lastQueryErrorInfo(); // array
    print_r($info);
}

```

Configuration
-------------

[](#configuration)

We need an folder with schemas of database.

```
$orm->schemas(__DIR__.'/schemas'); // path to configuration files schemas

```

schema example ( schemas/UserSchema.xml )

```

            TRUE
            FALSE
            FALSE

            1

            100

            100
            email@email.com

            TRUE
            TRUE

            FALSE
            TRUE

            TRUE
            FALSE

```

### Auto Generate Schemas (Terminal)

[](#auto-generate-schemas-terminal)

If your database is generated you can use the command line to generate the schemas.

example

```
> php bin/otter generate:schema:db --host=localhost --db=databaseName --user=sa --password=password123 --path=db/schemas --model=User --table=users

```

#### Arguments

[](#arguments)

argumentinfoexample value--hostThe host of database127.0.0.1--dbThe name of database to usedb\_disks--userThe username to loginsa--passwordThe password of user loginpassword123--pathThe to save the schemadb/schema--modelThe model nameUser--tableThe table name in databaseusersQueries
-------

[](#queries)

### SELECT

[](#select)

Simple examples

```
$users = $User->find()
              ->end();

$users = $User->findAll()
              ->end();

```

MethodinfoOptionsexamplefindReturn the first resultonlyColumns \[array\]find(\[ 'id', 'name', 'role.name' \])findAllReturn all resultsonlyColumns \[array\]find(\[ 'id', 'name', 'role.name' \])- The `find(...)` method is an alias for `findAll(...)->top(1)`

#### Filter Results

[](#filter-results)

This find all users that the name is **George**:

```
$User->findAll()
     ->where([
         'name' => 'George',
     ])
     ->end();

```

This find all users that the name is **George** or Id **1**:

```
$User->findAll()
     ->where([
         'name' => 'George',
         'or',
         'Id' => 1
     ])
     ->end();

```

This find first users that the name is **George** or **Philippe**:

```
use Otter\ORM\OtterValue;

$User->find()
     ->where([
        OtterValue::OR('name', 'George', 'Philippe'),
     ])
     ->end();

```

This find first users that the country is **EEUU**, name starts with **Ge** and id is more than 10:

```
$User->find()
     ->where([
         'country' => 'EEUU',
         'name' => ['LIKE', 'GE%'],
         'id' => ['>', 10]
     ])
     ->end();

```

Get top 10 results:

```
$User->findAll()
     ->top(10)
     ->end();

```

Get only id and name:

```
$User->findAll([
        'id',
        'name'
    ])
    ->end();

```

Order by:

```
$User->findAll([
        'id',
        'name'
    ])
    ->orderBy([
        'id',              // Ascendent
        'name' => 'DESC'   // Descendent
    ])
    ->end();

```

Group by:

```
$User->findAll([
        'country'
    ])
    ->groupBy([
        'country'
    ])
    ->end();

```

Count data:

```
$User->count()
     ->where([
        'country' => 'EEUU'
     ])
     ->end();

```

- This returns a number

Relations:

```
$User->find()
     ->include([
         'role'
     ])
     ->end();

```

- The join internals uses dependens of the configuration of schemas.
- [Go to relations for more details](#Relations)

### CREATE

[](#create)

```
$User->create([
    'name' => 'Joe',
    'country' => 'France',
]);

```

- This return a **boolean**
- No uses the end function
- Remember: We uses the configuration file. If a column is required and not passed, `DefaultValue` will be used or **NULL** will be used if allowed `AllowNull`

schemas/UserSchema.php

```
...

    ...

        30
        FALSE
        FALSE
        email@email.com // will be used

    ...

...

```

### UPDATE

[](#update)

```
$User->update([
    'country' => 'EEUU',
])
->where([
    'id' => 1
])
->end();

```

- **Don't forget** the `where` function if you don't want to update all the data in the table.

### DELETE

[](#delete)

```
$User->update([
    'country' => 'EEUU',
])
->where([
    'id' => 1
])
->end();

```

- **Don't forget** the `where` function if you don't want to delete all the data in the table.

Relationships
-------------

[](#relationships)

We uses 4 types of relations:

- BelongsTo
- BelongsToMany
- HasOne
- HasMany

### Belongs To

[](#belongs-to)

This is used for a relation like 1:1 or 1:1. For example, a user can have one or more roles (depending on the design). In both cases, we use BelongsTo in the user scheme.

schemas/UserSchema.xml

```
...

    ...

        Role
        id_role
        id
        TRUE           // optional

    ...

...

```

- The `name` attribute in association tag is the name for association (we used the name association for link the association)
- The `strict` option force to use Inner Join in select. By default we use *LEFT JOIN*

### Belongs To Many

[](#belongs-to-many)

This is used for a relation like N:1.

schemas/UserSchema.xml

```
...

    ...

        id_role
        UserRole
        role
        id_user

    ...

...

```

- The `name` attribute in association tag is the name for association (we used the name association for link the association)
- The `strict` option force to use Inner Join in select. By default we use *LEFT JOIN*
- The `through` tags indicate the intermediary model and the necessary options:
    - `through-bridge` indicate the association name used (eg. in UserRole)
    - `through-key` indicate the column to another model (eg. associate User to UserRole)

### Has One

[](#has-one)

This is used for a relation like 1:1. For example, a book have one author (usually).

schemas/BookSchema.xml

```
...

    ...

        Author
        id_author
        id
        TRUE           // optional

    ...

...

```

- The `name` attribute in association tag is the name for association (we used the name association for link the association)
- The `strict` option force to use Inner Join in select. By default we use *LEFT JOIN*

### Has Many

[](#has-many)

This is used for a relation like 1:N. For example, a book have one author (usually).

schemas/BookSchema.xml

```
...

    ...

        Author
        id_author
        id
        TRUE           // optional

    ...

...

```

- The `name` attribute in association tag is the name for association (we used the name association for link the association)
- The `strict` option force to use Inner Join in select. By default we use *LEFT JOIN*

Libre Query
-----------

[](#libre-query)

If you want, you can generate a query an execute.

```
Otter\ORM\Otter::db("SELECT * FROM persons");

```

- Returns `array|null`

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d0a8446e5f60bd1e384824f4de9a29e29db41c7512e3c74fd85dd522a07c422?d=identicon)[phgac](/maintainers/phgac)

---

Top Contributors

[![phGac](https://avatars.githubusercontent.com/u/38825265?v=4)](https://github.com/phGac "phGac (8 commits)")

---

Tags

no-dependenciesormorm-frameworkphp-orm-pdosql-server

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/otter-orm/health.svg)](https://phpackages.com/packages/otter-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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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