Skip to content

Simple, light-weight, mysql ORM for php7 with Django-like interface

License

Notifications You must be signed in to change notification settings

taggart-comet/php_my_orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php_my_orm

Simple, light-weight, MySql ORM for php7 with Django-like interface

Step #1: Creating a model

Wherever in your code define a model with table structure like this:

class TestModel extends PhpMyOrm\Model {

	public $table_name  = 'php_myorm_test_table';
	public $db_name     = 'test';
	public $description = 'This table is for tests';

	public function fields() {

		return [
			'id'         => new PhpMyOrm\IntField(true, true),
			'status'     => new PhpMyOrm\TinyIntField(),
			'date_added' => new PhpMyOrm\IntField(),
			'content'    => new PhpMyOrm\CharField(200),
			'extra'      => new PhpMyOrm\JSONField(),
		];
	}

	public function indexes() {

		return [
			['status'],
		];
	}
}

Step #2: Migrating the model

  • Insert paths to your models in ./conf.php:MODEL_CLASSES
  • Make sure migrate.php can 'see' your classes
  • Run this script: php ./migrate.php It will create tables.

Step #3: Using the model

Insert

$obj = new TestModel([
	'date_added' => time(),
]);
$obj->save();

Select

$obj = TestModel::objects()
	->filter_equal('status', 0)
	->order_desc('id')
	->get()

All the possible examples can be found in test classes in ./test/tests

About

Simple, light-weight, mysql ORM for php7 with Django-like interface

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages