update works with postgres

master
Matt Huntington 8 years ago
parent 9895e13f1c
commit 80bb52da21

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

@ -0,0 +1 @@
UPDATE people SET name = $1, age = $2 WHERE id = $3

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

Loading…
Cancel
Save