metodo editar crup api fetch

<?php
        $data = json_decode(file_get_contents("php://input"));
        require "conexion.php";
        $id = $data->id;
        $query = $pdo->prepare("SELECT * FROM productos WHERE id = :id");
        $query->bindParam(":id", $id, PDO::PARAM_INT);
        $query->execute();
        $result = $query->fetch(PDO::FETCH_ASSOC);
        echo json_encode($result);
        $pdo = null;
?>