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

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

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

Loading…
Cancel
Save