PHP code example of erwang / korm

1. Go to this page and download the library: Download erwang/korm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erwang / korm example snippets

 php
$connection = \KORM\Connection::setup('name','pdo_dsn', 'username', 'password');
 php
$connection = \KORM\Connection::setup('connectionName','mysql:host=localhost;dbname=database', 'username', 'password');
 php
$connection = \KORM\Connection::setup('connectionName','mysql:host=localhost;dbname=database', 'username', 'password', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
 php
Book::setConnection($connection);
 php
$book = new Book($id);
 php
$book = new Book();
 php
$book = new Book($id);
$book->title='Les Misérables';
$book->store();
 php
$book = new Book($id);
$book->delete();
 php
$book = Book::findOne(['title'=>'Les Misérables']);
 php
$authors = Author::find(['nationality'=>'French']);
 php
$books = Book::where('pages>:nbpages',['nbpages'=>100]);
 php
$books = Book::getAll();
 php
//create tags
$tag1=new Tag();
$tag1->text='french';
$tag1->store();

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

//find book from many
$booksWithFrenchTag = $tag1->book;
 php
//get the number of books
Book::count();

//get the number of books from an author
Book::count(['author_id'=>$author->id]);
 php
//get data from an array
$post=['firstname'=>'Marcel','lastname'=>'Proust'];
//create a new author
$author=new Author();
$author->populate($post);
$author->store();
 php
//with foreign key check
Author::truncate();
//without foreign key check
Author::truncate(false);
 php
//with foreign key check
Author::drop();
//without foreign key check
Author::drop(false);