1. Go to this page and download the library: Download legomolina/simple-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/ */
legomolina / simple-orm example snippets
use \SimpleORM\Model;
class MyModel extends Model
{
//Select the table which the model references
protected static function getTableName()
{
return 'my_table';
}
//OPTIONAL. Select the id field for the table. Default: 'id'
protected static function getTableId()
{
return 'my_table_id';
}
//Custom methods for this model
//public static function myMethod(my_params) { }
}
$result = MyModel::all()->get(1)->execute(); //get 1 without offset
$result = MyModel::all()->get(1, 2)->execute(); //get 1 with offset 2
$insert = array('field' => 'value', 'field' => 'value');
$result = MyModel::query()->insert($insert)->execute();
//$result => true if insertion is correct, false otherwise
$result = MyModel::query()->delete()->where('field', '=', 'value')->execute(); //important use where() with delete()
//$result => true if delete is correct, false otherwise
$update = array('field' => 'value', 'field' => 'value');
$result = MyModel::query()->update($update)->where('field', '=', 'value')->execute(); //important use where() with update()
//$result => true if update is correct, false otherwise
while($result->loop()) {
$field_1 = $result->table_field_1;
$field_2 = $result->table_field_2;
...
$field_n = $result->table_field_n;
//do something with the values
}
$result->first(); //loads first register
$result->next(); //loads next register if exists, otherwise it will return false
$result->prev(); //loads previous register if exists, otherwise it will return false
$result->last(); //loads last register