PHPackages                             xorm/xorm - 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. xorm/xorm

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

xorm/xorm
=========

It is simple orm solution in php

1.0.0(8y ago)2211[1 issues](https://github.com/flik/X/issues)MITPHPPHP &gt;=5.4.0

Since Jan 29Pushed 8y ago2 watchersCompare

[ Source](https://github.com/flik/X)[ Packagist](https://packagist.org/packages/xorm/xorm)[ Docs](https://github.com/flik/X.git)[ RSS](/packages/xorm-xorm/feed)WikiDiscussions master Synced 2mo ago

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

XORM
====

[](#xorm)

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

[](#installation)

You can install this package via Composer by running this command in your terminal in the root of your project:

```
composer require xorm/xorm:dev-master

use X as X; // Load class with composer  at the top of the file
// or
require '/X.php'; // Load direct without composer at the top of the file
```

Composer detail:

SETUP DATABASE
==============

[](#setup-database)

```
// setup($constr, $user, $pass, $debugConfig=0) $debugConfig 1 will show all queries before result
X::setup( 'mysql:host=localhost;dbname=mydb',  'username' ,  'password' ,0 );
```

SETUP TABLE FOR ADD / UPDATE / DELETE
=====================================

[](#setup-table-for-add--update--delete)

```
X::manage('users');
//$dbc['id'] = 1;
$dbc['title'] = 'test title';
X::save($dbc); //for save and update
```

REMOVE RECORD BY ID.
====================

[](#remove-record-by-id)

```
//It will find you primery coulumn auto and delete record. It does't matter primery column is id or bid.
X::delete('users' ,12);
```

GET ALL BY CUSTOM QUERY
=======================

[](#get-all-by-custom-query)

```
$sql = 'SELECT xdata FROM `users` WHERE 1 ';
$rec = X::getAll( $sql );
```

EXECUTE ALL QUERIES
===================

[](#execute-all-queries)

```
$sql = 'SELECT xdata FROM `users` WHERE 1 ';
$rec = X::exec_sql( $sql ); //SELECT, UPDATE, DELETE, ETC..
```

GET RECORD BY ID.
=================

[](#get-record-by-id)

```
//It will find you primery coulumn auto and show record
$rec = X::load('users' ,12 );
X::debug($rec);
```

GET ALL RELATED RECORDS BY TABLE NAME AND ID OR WITHOUT ID.
===========================================================

[](#get-all-related-records-by-table-name-and-id-or-without-id)

```
//It will return mixed data with auto joins
X::setRecursive(1);
$rec = X::load('users' ,12 );
X::debug($rec);

//It will return all related data in clasified way
X::setRecursive(2);
$rec = X::load('users' ,12 );
X::debug($rec);

$rec = X::load('users' );
X::debug($rec);
```

PAGINATION
==========

[](#pagination)

```
//paginate($length = 20, $current_page=5 )
$data = X::paginate(20,5);
```

EMPTY TABLE
===========

[](#empty-table)

```
 X::emptyX('users');
```

REMOVE TABLE
============

[](#remove-table)

```
 X::drop('users');
```

EXPORT CSV
==========

[](#export-csv)

```
X::download_send_headers("data_CSV_export_" . date("Y-m-d") . ".csv");
echo X::array2csv($data);
```

xml to Array
============

[](#xml-to-array)

```
$dataArray = X::xmltoArray($xmlstr);

```

FULL DETAIL
===========

[](#full-detail)

```
// setup($constr, $user, $pass, $debugConfig=0) $debugConfig 1 will show all queries before result
X::setup( 'mysql:host=localhost;dbname=st_mysite', 'root', 'm' ,1);

Here is example database structure. I have 2 tables in db1 and 1 table in db2. I have cross joins.

relation detail: db1

CREATE TABLE `albums` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `artist` varchar(100) NOT NULL,
  `title` varchar(100) NOT NULL,
  `user_id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `customer_id` (`customer_id`),
  CONSTRAINT `FK_AlbumsCustomers` FOREIGN KEY (`customer_id`) REFERENCES `db2`.`customers` (`id`),
  CONSTRAINT `FK_AlbumsUsers` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=latin1

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `data1` varchar(111) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1

-----------------------------------------------------
**db2.**
CREATE TABLE `customers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `state` varchar(50) DEFAULT NULL,
  `zip` varchar(15) DEFAULT NULL,
  `country` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=169 DEFAULT CHARSET=latin1.

/*
CREATE TABLE IF NOT EXISTS `AppVersion` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ClassName` enum('AppVersion') DEFAULT 'AppVersion',
  `LastEdited` datetime DEFAULT NULL,
  `Created` datetime DEFAULT NULL,
  `Version` varchar(12) DEFAULT NULL,
  `Mandatory` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `Link` varchar(255) DEFAULT NULL,
  `Platform` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `ClassName` (`ClassName`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=470 ;

--
-- Dumping data for table `AppVersion`
--

INSERT INTO `AppVersion` (`ID`, `ClassName`, `LastEdited`, `Created`, `Version`, `Mandatory`, `Link`, `Platform`) VALUES
(3, 'AppVersion', '2016-01-20 19:47:09', '2016-01-20 19:47:09', '1.0.1', 1, 'http://apple.com', 'ios'),
(4, 'AppVersion', '2016-01-20 19:47:09', '2016-01-20 19:47:09', '1.0.1', 1, 'http://google.com', 'android'),
(7, 'AppVersion', NULL, NULL, '1.0.2', 1, 'http://apple.com', 'ios'),
(8, 'AppVersion', NULL, NULL, '1.0.6', 0, 'http://apple.com', 'ios'),
(9, 'AppVersion', NULL, NULL, '1.0.10', 1, 'http://apple.com', 'ios');
*/

X::manage( 'AppVersion');

$data = X::select('Mandatory, Platform'); // PUT FIELD STATMENT LIKE FIEL1 AS F, FIELD2 AS B, FIELD3

$data = X::where('Version','like','1.0.2'); //WHERE WORK WITH AND OPERATOR

$data = X::where('Platform','=','ios');

$data = X::groupBy('Mandatory');

$data = X::limit(1,5);

$data = X::where('Mandatory','=',0);

$data = X::orderBy('Mandatory','DESC');

//paginate($length = 10, $current_page=1 )

$data = X::paginate(20,5);

//$data = X::whereOr('Mandatory','=',0); //It IS FOR OR CONDITION

//$data = X::where(1); //IT WILL RETURN WHOLE TABLE DATA

//$data = X::where(); //IT WILL RETURN WHOLE TABLE DATA
```

---

//

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3031d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc1a64396a93deefc614cf23851c748d281f41081b23bc87eb2947d150853bca?d=identicon)[flik](/maintainers/flik)

---

Top Contributors

[![flik](https://avatars.githubusercontent.com/u/900323?v=4)](https://github.com/flik "flik (46 commits)")

---

Tags

ormxorm

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k241.3M3.3k](/packages/doctrine-doctrine-bundle)[doctrine/persistence

The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.

4.1k286.5M762](/packages/doctrine-persistence)[gedmo/doctrine-extensions

Doctrine behavioral extensions

4.1k118.8M366](/packages/gedmo-doctrine-extensions)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[beberlei/doctrineextensions

A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL, Oracle, PostgreSQL and SQLite.

2.1k75.1M146](/packages/beberlei-doctrineextensions)

PHPackages © 2026

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