PHP code example of taq / torm

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

    

taq / torm example snippets



// open the PDO connection and set it
$con = new PDO("sqlite:database.sqlite3");
TORM\Connection::setConnection($con);
TORM\Connection::setDriver("sqlite");

// define your models - an User class will connect to an users table
class User extends TORM\Model {};
class Ticket extends TORM\Model {};

// create some validations
User::validates("name",  ["presence"     => true]);
User::validates("email", ["presence"     => true]);
User::validates("email", ["uniqueness"   => true]);
User::validates("id",    ["numericality" => true]);

// create some relations
User::hasMany("tickets");
User::hasOne("account");
Ticket::belongsTo("user");

// this will create a new user
$user = new User();
$user->name  = "John Doe";
$user->email = "[email protected]";
$user->level = 1;
$user->save();

// this will find the user using its primary key
$user = User::find(1);

// find some users
$users = User::where(["level" => 1]);

// find some users, using more complex expressions
// the array first element is the query, the rest are values
$users = User::where(["level >= ?", 1]); 

// updating users
User::where(["level" => 1])->updateAttributes(["level" => 3]);

// using fluent queries
$users = User::where(["level" => 1])->limit(5)->order("name desc");

// listing the user tickets
foreach($user->tickets as $ticket) {
   echo $ticket->description;
}

// show user account info
echo $user->account->number; 
bash
$ php -r 'phpinfo();' | grep 'php.ini'
Configuration File (php.ini) Path => /etc/php/7.1/cli
Loaded Configuration File => /etc/php/7.1/cli/php.ini
bash
$ sudo apt install php-sqlite3

$ sudo apt install php-mbstring php-intl php-yaml