PHP Classes

Simple PHP ORM: Manage objects stored in a database using a ORM

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 212 All time: 8,347 This week: 455Up
Version License PHP version Categories
simpleorm 1.0.0GNU General Publi...5PHP 5, Databases, Design Patterns
Description 

Author

This package can manage objects stored in a database using a ORM.

It provides a fluent interface to create objects from scratch or retrieved from databases.

It can also establish relationships between objects from records of different tables.

Picture of Duong Huynh Nghia
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Documentation

simpleORM

PHP ORM Database in simplest way.

Installation:

Include autoload file of SimpleORM to your project require_once '../SimpleORM/autoload.php';

Config Database Connector

$configs = array( 
    'host' => 'localhost', // host name
    'name' => 'd2_test2', //db name
    'user' => 'root', //user db
    'pwd' => '123456',//password db
    'port' => 3306, // port connector
    'prefix' => 'tbl_', // prefix for tables
    'adapter' => 'mysqli', // adapter, supported MySQLi and PDO
    'charset' => 'utf8', // charset of connector
	  'type' => 'mysql' // type of connection in case using PDO
 );
$db = new Connector($configs);

Usage

??? Look the database sql file in folder "test/d2_test2.sql".

New Model

$oModel = new Model("client");
$oModel->getTable()->setPrimaryKey("client_id"); // should set primary key for table

Create Query

$query = $oModel->createQuery();

How to get all "clients" with filter

$mData = $oModel->createQuery()->where('client_id',1,'>')->select('*')->getAll();

Setup relationship tables

$oRelation = new Relation($this);
		// 1-1
		$oRelation->hasOne('info',array(
			'source' => 'client_id', // from table column
			'target' => 'client_id', // to target table column
			'table' => 'client_info' // target table
		));
		// 1-n
		$oRelation->hasMany('apps',array(
			'source' => 'client_id',
			'target' => 'client_id',
			'table' => 'client_app'
		));
		// n-1
		$oRelation->belongsTo('client_type',array(
			'source' => 'level',
			'target' => 'id',
			'table' => 'client_type',
		));
		// n- n with bride(junction) table client_group
		$oRelation->hasManyToMany('groups',array(
				'source' => 'client_id', // from table column
				'target' => 'id', // to target table column
				'table' => 'group', // target table
				'option' => array(
						'bridge' => array(
								'table' => 'client_group', // junction table
								'source' => array(
									'client_id' => 'client_id' // mapping junction table & source table
								),
								'target' => array(
										'id' => 'group_id',// mapping junction table & target table
								)
						)
				)
		));

Advanced usage

  • It's allowed to extend all of class such as: Model, Table, Reference and Relation, Even the Row Data.
  • Look more at the folder "test/DbTest/Client".
  • You can extend and write any advanced functions.

  Files folder image Files (38)  
File Role Description
Files folder image.settings (2 files)
Files folder imageSimpleORM (1 file, 3 directories)
Files folder imagetest (9 files, 1 directory)
Accessible without login Plain text file .buildpath Data Auxiliary data
Accessible without login Plain text file .project Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:212
This week:0
All time:8,347
This week:455Up