1. Go to this page and download the library: Download sourcegr/freakquent 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/ */
sourcegr / freakquent example snippets
use Sourcegr\QueryBuilder\DB;
use Sourcegr\Freakquent\Freakquent;
use Sourcegr\QueryBuilder\Grammars\MySQL;
$grammar = new MySQL([
'DB' => 'dbname',
'USER' => 'user',
'PASS' => 'passwordd',
'HOST' => '127.0.0.1'
]);
$DB = new DB($grammar);
Freakquent::init($DB);
namespace Models;
use Sourcegr\Freakquent\BaseModel;
use Sourcegr\Freakquent\Relations\RelationTrait;
class Contact extends BaseModel
{
use RelationTrait;
protected static $table = 'contacts';
public $id;
public $name;
public $company_id;
public function company() {
return $this->belongsTo(Company::class, 'company_id', 'id');
}
}
namespace Models;
use Sourcegr\Freakquent\BaseModel;
use Sourcegr\Freakquent\Relations\RelationTrait;
class Company extends BaseModel
{
use RelationTrait;
// set up model's database tablename
protected static $table = 'companies';
// set up model's database columns
public $id;
public $name;
// set up a relation. A Company has many contacts
public function contacts()
{
return $this->hasMany(Contact::class, 'id', 'company_id');
}
}