PHP code example of colorium / orm

1. Go to this page and download the library: Download colorium/orm 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/ */

    

colorium / orm example snippets


use Colorium\Orm\MySQL;

$mysql = new MySQL('dbname');

use Colorium\Orm\MySQL;

$mysql = new MySQL('dbname', [
    'user' => My\App\User::class
]);

$users = $mysql->user->fetch();
$users = $mysql->user->where(...)->sort(...)->limit(...)->fetch();

$users = $mysql->user->where('age', 27)->fetch();
$users = $mysql->user->where('age >', 27)->fetch();
$users = $mysql->user->where('age', [25, 26, 27]])->fetch();
// or multiple where
$users = $mysql->user->where(['age' => 27, 'eyes' => 'green'])->fetch();

$users = $mysql->user->sort('city')->fetch(); // ASC
$users = $mysql->user->sort('city', SORT_DESC)->fetch();

$users = $mysql->user->limit(5)->fetch(); // 5 records from start
$users = $mysql->user->limit(5, 10)->fetch(); // 10 records from the 5th

$user = $mysql->user->one(); // first record
$user = $mysql->user->where(...)->one();

$id = $mysql->user->add([
    'username' => 'New player'
]);

$user = $mysql->user->where('id' => 15)->one();

$user->username = 'Old player';
$mysql->user->where('id', 15)->edit($user);

$mysql->user->where('id' => 15)->drop();

$users = $mysql->raw('select * from `user`');

Use Colorium\Orm\Hub;

Hub::source($mysql);

$users = Hub::user()->fetch();

class User
{
    use Colorium\Orm\Model;
    
    /** @var int */
    public $id;
    
    /** @var string */
    public $username;
    
    /** @var string */
    public $password;
}

$user = User::one(['id' => 15]);

$user->username = 'Winner';
$user->save();