2017 © Pedro PelĂĄez
 

library korm

ORM for PHP

image

erwang/korm

ORM for PHP

  • Thursday, August 10, 2017
  • by erwang
  • Repository
  • 1 Watchers
  • 0 Stars
  • 83 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

KORM

ORM in PHP ⛔ DEPRECATED, (*1)

Setup

The Connection class setup must be call first., (*2)

``` php $connection = \KORM\Connection::setup('name','pdo_dsn', 'username', 'password');, (*3)


A connection to a mysql database : ``` php $connection = \KORM\Connection::setup('connectionName','mysql:host=localhost;dbname=database', 'username', 'password');

with options :, (*4)

``` php $connection = \KORM\Connection::setup('connectionName','mysql:host=localhost;dbname=database', 'username', 'password', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));, (*5)


## Create a class Each table in database requires a class with the same name : ``` php class Table extends \KORM\Object{ }

name class is converted to lower case For example, to store books :, (*6)

``` php class Book extends \KORM\Object{ }, (*7)


The `Book` objects will be store in `book` table ## Define connection ``` php Book::setConnection($connection);

Get a row from id

``` php $book = new Book($id);, (*8)


will load in `$book` all the data in table `book` with id=1 ## Create a row ``` php $book = new Book();

Store an object

``` php $book = new Book($id); $book->title='Les Misérables'; $book->store();, (*9)


## Delete an object ``` php $book = new Book($id); $book->delete();

Find objects

Find one Object

``` php $book = Book::findOne(['title'=>'Les Misérables']);, (*10)


This return one Book (the first found) ### Find multiple Objects ``` php $authors = Author::find(['nationality'=>'French']);

This will return an array with all french authors, (*11)

If you need complex where clause, you can use where, (*12)

``` php $books = Book::where('pages>:nbpages',['nbpages'=>100]);, (*13)

This will return an array with books with more than 100 pages

If you want more complex queries :

``` php
$books = Book::query('select book.* from book,author where author.id=:author_id and pages>:nbpages and author.id=book.author_id',['nbpages'=>100,'author_id'=>1]);

This will return an array with books with more than 100 pages from author with id 1, (*14)

``` php $books = Book::getAll();, (*15)

This will return all books in table


## Relations

### One to many

``` php
//create a book
$lesMiserables = new Book();
$lesMiserables->title='Les Misérables';
$lesMiserables->store();

//create an author
$hugo=new Author();
$hugo->name='Victor Hugo';
$hugo->store();

//create a relation
$lesMiserables->author=$hugo;
$lesMiserables->store();

//get the book
$book = new Book($lesMiserables->id);
$author = $book->author; //return the object Author from table author

many to many

``` php //create tags $tag1=new Tag(); $tag1->text='french'; $tag1->store();, (*16)

$tag2=new Tag(); $tag2->text='Roman'; $tag2->store(); $lesMiserables->tag=[$tag1,$tag2]; $lesMiserables->store();, (*17)

//find book from many $booksWithFrenchTag = $tag1->book;, (*18)


## Count ``` php //get the number of books Book::count(); //get the number of books from an author Book::count(['author_id'=>$author->id]);

Populate an object

``` php //get data from an array $post=['firstname'=>'Marcel','lastname'=>'Proust']; //create a new author $author=new Author(); $author->populate($post); $author->store();, (*19)


## Truncate table ``` php //with foreign key check Author::truncate(); //without foreign key check Author::truncate(false);

Drop table

php //with foreign key check Author::drop(); //without foreign key check Author::drop(false);, (*20)

The Versions

10/08 2017

dev-master

9999999-dev

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

28/07 2017

v2.0.0

2.0.0.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

25/02 2017

v1.0.2

1.0.2.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

25/02 2017

v1.0.3

1.0.3.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

25/02 2017

v1.0.4

1.0.4.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

09/02 2017

v1.0.1

1.0.1.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

18/01 2017

v1.0.0

1.0.0.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping

29/12 2016

v0.0.15

0.0.15.0

ORM for PHP

  Sources   Download

gnu-gpl3

The Development Requires

by Avatar erwang

orm mapping