PHP REST API CRUD – Step 11

PHP REST API CRUD – Step 11

Step 11 Delete Data

  • Last, but not the least we will delete the user data. For this we will add delete functions in user.php of object folder.
// Delete User
    public function delete($id)
    {
        $query = "delete from " . $this->table . " where id= " . $id;
        try {
            $stmt = $this->conn->prepare($query);
            $stmt->execute();
            return true;
        } catch (PDOException $e) {
            {
                echo json_encode(array("DeleteUserSQLError" => $e->getMessage()));die;
            }
        }
    }

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*