PHP code example of riverside / php-orm

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

    

riverside / php-orm example snippets





putenv("DEFAULT_USERNAME=your_username");
putenv("DEFAULT_PASSWORD=your_password");
putenv("DEFAULT_DATABASE=your_database");
putenv("DEFAULT_HOST=localhost");
putenv("DEFAULT_PORT=3306");
putenv("DEFAULT_DRIVER=mysql");
putenv("DEFAULT_CHARSET=utf8mb4");
putenv("DEFAULT_COLLATION=utf8mb4_general_ci");


use Riverside\Orm\DB;

class User extends DB
{
    protected $table = 'users';
    
    protected $attributes = ['id', 'name', 'email'];
    
    // protected $connection = 'backup';
    
    public static function factory()
    {
        return new self();
    }
}

$id = User::factory()->insert(['name' => 'Chris', 'email' => '[email protected]']);
$user = User::factory()->where('id', $id)->get();
$affected_rows = User::factory()->where('id', $id)->update(['name' => 'Chris Johnson']);
$affected_rows = User::factory()->where('id', $id)->delete();

$db = new \Riverside\Orm\DB();
$db->table('users')->get();

$ curl -sS https://getcomposer.org/installer | php

$ php composer.phar install