PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (38)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-05-29 (5 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 44 This week: 44All time: 8,864 This week: 12Up
Version License PHP version Categories
simpleorm 1.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.

  Performance   Level  

Details

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  
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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:44
All time:8,864
This week:12Up