|
|
|
@ -1,43 +1,41 @@
|
|
|
|
<?
|
|
|
|
<?
|
|
|
|
include_once __DIR__ . '/../database/db.php';
|
|
|
|
include_once __DIR__ . '/../database/db.php';
|
|
|
|
|
|
|
|
|
|
|
|
class Person {
|
|
|
|
class Company {
|
|
|
|
public $id;
|
|
|
|
public $id;
|
|
|
|
public $name;
|
|
|
|
public $name;
|
|
|
|
public $age;
|
|
|
|
public function __construct($id, $name) {
|
|
|
|
public function __construct($id, $name, $age) {
|
|
|
|
|
|
|
|
$this->id = $id;
|
|
|
|
$this->id = $id;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->age = $age;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class People {
|
|
|
|
class Companies {
|
|
|
|
static function find(){
|
|
|
|
static function find(){
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/people/find.sql');
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/companies/find.sql');
|
|
|
|
$result = pg_query($query);
|
|
|
|
$result = pg_query($query);
|
|
|
|
$people = array();
|
|
|
|
$companies = array();
|
|
|
|
while($data = pg_fetch_object($result)){
|
|
|
|
while($data = pg_fetch_object($result)){
|
|
|
|
$people[] = new Person(intval($data->id), $data->name, intval($data->age));
|
|
|
|
$companies[] = new Company(intval($data->id), $data->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $people;
|
|
|
|
return $companies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static function create($person){
|
|
|
|
static function create($company){
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/people/create.sql');
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/companies/create.sql');
|
|
|
|
$result = pg_query_params($query, array($person->name, $person->age));
|
|
|
|
$result = pg_query_params($query, array($company->name));
|
|
|
|
|
|
|
|
|
|
|
|
return self::find();
|
|
|
|
return self::find();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static function delete($id){
|
|
|
|
static function delete($id){
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/people/delete.sql');
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/companies/delete.sql');
|
|
|
|
$result = pg_query_params($query, array($id));
|
|
|
|
$result = pg_query_params($query, array($id));
|
|
|
|
|
|
|
|
|
|
|
|
return self::find();
|
|
|
|
return self::find();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static function update($id, $updatedPerson){
|
|
|
|
static function update($id, $updatedCompany){
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/people/update.sql');
|
|
|
|
$query = file_get_contents(__DIR__ . '/../database/sql/companies/update.sql');
|
|
|
|
$result = pg_query_params($query, array($updatedPerson->name, $updatedPerson->age, $id));
|
|
|
|
$result = pg_query_params($query, array($updatedCompany->name, $id));
|
|
|
|
|
|
|
|
|
|
|
|
return self::find();
|
|
|
|
return self::find();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|