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

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

jijihohococo/ichi-orm
=====================

ORM for PHP

3.3(1mo ago)3781MITPHPPHP &gt;=7.3|&gt;=8.0CI passing

Since Dec 12Pushed 2mo ago1 watchersCompare

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

READMEChangelog (8)DependenciesVersions (24)Used By (1)

Ichi ORM
========

[](#ichi-orm)

Ichi ORM is aimed to be the fast performance and secure database ORM for PHP with simple usage.

License
-------

[](#license)

This package is Open Source According to [MIT license](LICENSE.md)

Table of Contents
-----------------

[](#table-of-contents)

- [Ichi ORM](#ichi-orm)
    - [License](#license)
    - [Table of Contents](#table-of-contents)
    - [Installation](#installation)
    - [Set up Database Connection](#set-up-database-connection)
        - [Available Database Setting](#available-database-setting)
    - [Table Structure](#table-structure)
    - [Create Model From Commandline](#create-model-from-commandline)
    - [Configuration Table Name](#configuration-table-name)
    - [Configuration Primary Key](#configuration-primary-key)
    - [CRUD](#crud)
        - [Create](#create)
            - [Disable Auto increment Id](#disable-auto-increment-id)
        - [Insert Multiple Rows In One Query](#insert-multiple-rows-in-one-query)
        - [Retrieve](#retrieve)
            - [Refers To](#refers-to)
            - [Refers Many](#refers-many)
        - [Update](#update)
        - [Update Multiple Rows In One Query](#update-multiple-rows-in-one-query)
        - [Delete](#delete)
    - [Querying](#querying)
        - [SELECT](#select)
        - [Getting Query Data](#getting-query-data)
            - [Get](#get)
            - [To Array](#to-array)
            - [Get Query Data With Soft Deleted Data](#get-query-data-with-soft-deleted-data)
        - [LIMIT](#limit)
        - [WHERE](#where)
        - [OR WHERE](#or-where)
        - [WHERE IN](#where-in)
        - [WHERE NOT IN](#where-not-in)
        - [Join](#join)
            - [Inner Join](#inner-join)
            - [Left Join](#left-join)
            - [Right Join](#right-join)
        - [Union](#union)
        - [Pagination](#pagination)
            - [Database Pagination](#database-pagination)
            - [Array Pagination](#array-pagination)
        - [Subqueries](#subqueries)
    - [Using PDO Functions](#using-pdo-functions)
    - [Using Different Databases](#using-different-databases)
    - [JSON Response](#json-response)
    - [Caching](#caching)
    - [Observers](#observers)

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

[](#installation)

```
composer require jijihohococo/ichi-orm
```

Set up Database Connection
--------------------------

[](#set-up-database-connection)

This library can connect MySQL, Postgres and MS SQL Server.

Firstly, you need to declare your database driver like below.

```
use JiJiHoHoCoCo\IchiORM\Database\Connector;

$connector = new Connector;
$connector->createConnection('mysql',[
	'dbname' => 'database_name',
	'charset' => 'utf8mb4',
	'collation' => 'utf8mb4_unicode_ci',
	'host' => '127.0.0.1',
	'user_name' => 'user_name',
	'user_password' => 'user_password'
]);
```

If you want to add another custom database connection, you can do just like that.

You must add dbname,host,user\_name and user\_password in your database connection. I recomend you to use "utf8mb4" for your database charset and "utf8mb4\_unicode\_ci" for your database collation.

*In defalt database connections, you don't need to add driver parameters but in your custom database connection you have to add driver parameters.*

```
$connector->addConnection('new_mysql_connection')->createConnection('new_mysql_connection',[
	'driver' => 'mysql',
	'dbname' => 'database_name',
	'charset' => 'utf8mb4',
	'collation' => 'utf8mb4_unicode_ci',
	'host' => '127.0.0.1',
	'user_name' => 'user_name',
	'user_password' => 'user_password'
]);
```

Default database connections are 'mysql' , 'pgsql' and 'sqlsrv'.

Supported database drivers are 'mysql' , 'pgsql' and 'sqlsrv'.

After declaring database connection, you can select default database connection

```
$connector->selectConnection('mysql');
```

### Available Database Setting

[](#available-database-setting)

NameDescriptionRequireddriverDatabase driver name✓dbnameDatabase name✓charsetCharset FontcollationCollation Font Setting for MySQL and Postgres SQLhostDatabase Host Address✓user\_nameDatabase User Name✓user\_passwordDatabase User Password✓unix\_socketUnix Socket For MySQLportDatabse Port Numberstrict (bool)Strict Mode In MySQLtime\_zoneDatabase Time Zone in MySQL and Postgres SQLisolation\_levelTo set Isolation Level in MySQLmodes (array)To set sql\_mode in MySQLsynchronous\_commitTo set Synchronous Commit in Postgres SQLsslmodeTo set SSL Mode in Postgres SQLsslcertTo set SSL Certificate in Postgres SQLsslkeyTo set SSL Key in Postgres SQLsslrootcertTo set SSL Root Certificate in Postgres SQLreadOnly (bool)True To set ApplicationIntent to ReadOnly in MS SQL Serverpooling (bool)True To set ConnectionPooling to true in MS SQL Serverapplication\_nameTo set APP in MS SQL Server OR application name in Postgres SQLencryptTo set ENCRYPT in MS SQL Servertrust\_server\_certificateTo set TrustServerCertificate in MS SQL Servermultiple\_active\_result\_setsTo set MultipleActiveResultSets in MS SQL Servertransaction\_isolationTo set TransactionIsolation in MS SQL Servermulti\_subnet\_failoverTo set MultiSubnetFailover in MS SQL Servercolumn\_encryptionTo set ColumnEncryption in MS SQL Serverkey\_store\_authenticationTo set KeyStoreAuthentication in MS SQL Serverkey\_store\_principal\_idTO set KeyStorePrincipalId in MS SQL Serverkey\_store\_secretTo set KeyStoreSecret in MS SQL Serverlogin\_timeoutTo set LoginTimeout in MS SQL ServerTable Structure
---------------

[](#table-structure)

If you have the column named "deleted\_at", be sure that the column is NULLABLE column.

Create Model From Commandline
-----------------------------

[](#create-model-from-commandline)

Firstly you need to created the file named "ichi" under your project folder and use the below code in this file

```
#!/usr/bin/env php
