PHP code example of danielefavi / slim-orm

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

    

danielefavi / slim-orm example snippets


   $config = [
       'connection' => 'mysql',
       'name' => 'database-name',
       'username' => 'root',
       'password' => 'your_password',
       'options' => [
           \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
       ],
   ];

   $pdo = new \PDO(
       'mysql:host=' . $config['connection'] . ';dbname=' . $config['name'],
       $config['username'],
       $config['password'],
       $config['options']
   );

   $db = DB::init($pdo);

   $pdo = new \PDO('sqlite:' . __DIR__ . '/sqlite.db');
   
   $db = DB::init($pdo);

$res = DB::table('users')
   ->where('name', 'Piripoppi')
   ->orWhere('age', '>=', 30)
   ->get();

$res = DB::table('users')
   ->orWhere('age', '>=', 30)
   ->paginate(10);

$res = DB::table('users')
   ->join('comments', '`users`.`id`', '=', '`comments`.`user_id`');
   ->where('id', '>', 30)
   ->where('id', '<=', 44)
   ->where(function($query) {
      $query->where('age', '>=', 10)
         ->orWhere('age', '<=', 20);
   })
   ->where(function($query) {
      $query->whereNull('age')
         ->orWhere('age', 20000);
   })
   ->orderByAsc('id')
   ->orderByDesc('file')
   ->orderBy('file', 'asc', 'field1', 'field2', 'desc', 'field3')
   ->limit(5)
   ->offset(3)
   ->groupBy('file', 'id')
   ->get();

use DfTools\SlimOrm\Model;

class UserModel extends Model
{
    protected $table = 'users';

    protected $primaryKey = 'id';
}

./vendor/bin/phpunit