Introduction Last updated: 04/10/2020

PHPtricks-ORM A database Library which uses the PDO extension.

  • Allows one connection with the database and deny duplicate connections,
    this speeds up to use the database and reduces the load on the server.
  • supports many drivers (mysql, sqlite, PostgreSQL, mssql, sybase, Oracle Call Interface -oci-).
  • it makes communication easy with databases and perform operations on tables with ease.
Github Repository:

Find phptricks-ORM Source Code in github

Overview

Start Using PHPtricks-ORM. It won't take more than 5 minutes to start. Read the step-by-step guide.

  • Create Users Table

    first thing we want to create users_table migration via command-line.

    php phptricks migrate:make UsersTable create -table=users
    
  • Edit Migration Class

    Navigate to migration directory and open UsersTable.php
    and change table schema.

    <?php
    
    require_once 'vendor/autoload.php';
    
    use PHPtricks\Orm\Builder;
    class UsersTable extends Builder
    {
        protected $_table = 'users';
    
        public function run()
        {
            return $this->schema([
                'id' => 'increments',
                'username' => 'string:255|not_null|unique',
                'is_active' => 'int|default:0',
                'email' => 'string:255|not_null|unique',
                'created_at' => 'timestamp',
            ])->create();
        }
    }
    
  • Migrate Table

    migrate table to database via command-line

    php phptricks migrate
    
  • Create Users Model

    create users model via command-line



    Generated Class
    php phptricks model UserModel --table=users
    


    use PHPtricks\Orm\Model;
    class UserModel extends Model
    {
        protected $_table = 'users';
    }
    
  • Insert Some Data

    insert some data into users table

    $user = new UsersModel();
    $user->insert([
        'username' => 'al-anzawi',
        'email' => 'm.anzawi2013@gmail.com'
    ]);
    
  • get all records from users table

    SELECT * FROM users

    $allUsers = $user->select();
    


Learn More About :

  1. Migrations
  2. Models
  3. Insert Data
  4. Retrieve Data

Need a Help ?

feel free to contact me on < m.anzawi2013@gmail.com >

Fork On Github

Fork PHPtricks-ORM Library on Github and help me to develop something awesome