PHP REST API CRUD – Step 9
Step 9 Update Data
- After view/read user, now we update the user data. For this we will add update functions in user.php of object folder
//Update User Data
public function update($id)
{
$query = "update " . $this->table . " set name=?,email=?,password=? where id= " . $id;
try {
$stmt = $this->conn->prepare($query);
$run = $stmt->execute([$this->name, $this->email, $this->password]);
return true;
} catch (PDOException $e) {
{
echo json_encode(array("UpdateDataSQLError" => $e->getMessage()));die;
}
}
}