PHP code example of it-tech / orm

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

    

it-tech / orm example snippets



use ITTech\ORM\Model;

class User extends Model
{
    /*
     * Таблица модели
     */
    protected $table = "users";
}


use ITTech\ORM\Connect;

$data = [
    "host"     => "localhost",
    "port"     => 3306,
    "database" => "test",
    "user"     => "root",
    "password" => "1234",
    "charset"  => "utf8"
];

Connect::create($data);

/*
 * Выбор из таблицы с условием
 */
$result = User::where("enable", 1)->get();

/*
 * Выбор из таблицы с условием
 */
$result = User::where("enable", 1)
            ->where("id", ">", 9)->get();
            
/*
 * Выбор из таблицы с условием
 * Сортировка выбора
 */
$result = User::where("enable", 1)
            ->orderby("name", "DESC")->get();

/*
 * Выбор по идентификатору
 */
$result = User::find(1);

$model           = new User();
$model->name     = "Вася";
$model->password = 1234;

$model->save();

$model       = User::find(1);
$model->name = "Петя";

$model->save();

User::find(1)->drop();