create uses postgres

master
Matt Huntington 8 years ago
parent eba77ba9fa
commit 1cad051928

@ -7,7 +7,7 @@ if($_REQUEST['action'] === 'index'){
} else if ($_REQUEST['action'] === 'post'){
$requestBody = file_get_contents('php://input');
$body = json_decode($requestBody);
$newPerson = new Person($body->name, $body->age);
$newPerson = new Person(null, $body->name, $body->age);
$allPeople = People::create($newPerson);

@ -0,0 +1 @@
INSERT INTO people (name, age) VALUES ($1, $2)

@ -24,15 +24,10 @@ class People {
return $people;
}
static function create($person){
$people = array();
$people[] = new Person('joni', 52);
$people[] = new Person('bob', 34);
$people[] = new Person('sally', 21);
$people[] = new Person('matt', 37);
$people[] = $person;
$query = file_get_contents(__DIR__ . '/../database/sql/create.sql');
$result = pg_query_params($query, array($person->name, $person->age));
return $people;
return self::find();
}
static function delete($index){
$people = array();

Loading…
Cancel
Save