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  
Name: Duong Huynh Nghia <contact>
Classes: 4 packages by
Country: Viet Nam Viet Nam

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

  Files folder image Files  /  .settings  
File Role Description
  Accessible without login Plain text file org.eclipse.php.core.prefs Data Auxiliary data
  Accessible without login Plain text file org.eclipse.wst.co...ject.facet.core.xml Data Auxiliary data

  Files folder image Files  /  SimpleORM  
File Role Description
Files folder imageAdapter (4 files)
Files folder imageDb (5 files)
Files folder imageHelper (6 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  SimpleORM  /  Adapter  
File Role Description
  Plain text file DbMockup.php Class Class source
  Plain text file IAdapter.php Class Class source
  Plain text file Mysqli.php Class Class source
  Plain text file PDO.php Class Class source

  Files folder image Files  /  SimpleORM  /  Db  
File Role Description
  Plain text file Model.php Class Class source
  Plain text file Reference.php Class Class source
  Plain text file Relation.php Class Class source
  Plain text file Row.php Class Class source
  Plain text file Table.php Class Class source

  Files folder image Files  /  SimpleORM  /  Helper  
File Role Description
  Plain text file Connector.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file Object.php Class Class source
  Plain text file Query.php Class Class source
  Plain text file Tool.php Class Class source
  Plain text file Validator.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imageDbTest (1 file, 2 directories)
  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 d2_test2.sql Data Auxiliary data
  Accessible without login Plain text file dbconfig.php Aux. Auxiliary script
  Accessible without login Plain text file generate-db-config.php Example Example script
  Accessible without login Plain text file generate-model.php Example Example script
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file test-validator.php Example Example script
  Accessible without login Plain text file using-dynamic-mapper.php Example Example script

  Files folder image Files  /  test  /  DbTest  
File Role Description
Files folder imageClient (5 files)
Files folder imageClientApp (2 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  test  /  DbTest  /  Client  
File Role Description
  Plain text file Model.php Class Class source
  Plain text file Reference.php Class Class source
  Plain text file Relation.php Class Class source
  Plain text file Row.php Class Class source
  Plain text file Table.php Class Class source

  Files folder image Files  /  test  /  DbTest  /  ClientApp  
File Role Description
  Plain text file Model.php Class Class source
  Plain text file Table.php Class Class source

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