1. Go to this page and download the library: Download romagny13/micro-db 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/ */
use \MicroPHP\Db\Model;
class PostModel extends Model
{
public function __construct()
{
$this->table = 'posts';
}
}
use \MicroPHP\Db\Model;
class PostModel extends Model
{
public function __construct()
{
$this->table = 'posts';
$this->columns = ['id','title','content','user_id'];
}
}
class UserModel extends Model
{
public function __construct()
{
$this->table = 'users';
}
}
class CategoryModel extends Model
{
public function __construct()
{
$this->table = 'categories';
}
}
class PostModel extends Model
{
public function __construct()
{
$this->table = 'posts';
$this->columns = ['title','content'];
// relations
$this->addRelation('users',['user_id' => 'id'],UserModel::class, 'user');
$this->addRelation('categories',['category_id' => 'id'],CategoryModel::class, 'category');
}
}
$post = PostModel::find(Condition::op('id',1));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.