PHP code example of sandeshshrestha / tiny-orm

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

    

sandeshshrestha / tiny-orm example snippets


// Define __FILE_STORAGE_PATH__ constant where the FileStorage::save() method saves the file.
define("__FILE_STORAGE_PATH__", __DIR__ . '/uploaded_files/');
// Define __DATABASE_CONFIG__ constant that will be used by Database.php to connect to database
define("__DATABASE_CONFIG__", [
    'type' => 'mysql',
    'host' => 'mysql.example.com',
    'username' => 'db_username',
    'password' => 'db_password',
    'database' => 'db_name',
    'table_prefix' => 'db_table_prefix',
    'port' => 3306
  ]);


use TinyORM\Model;

class User extends Model {
  protected $table = 'user';
  protected $primaryKey = 'id';
  protected $fillable = ["fullName", "email"];
}

$user = new User();
$user->fullName = "John Doe";
$user->email = "[email protected]";
$user->save();

$user2 = User::create([
  'fullName' => "John Doe 2",
  "email" => "[email protected]",
]);

$foundUser = User::find($user->getPrimaryValue());

$foundUser->delete();

$users = User::where("fullName", "John Doe")->limit(1)->orderBy('id')->exec();