Пример #1
0
    $book = new Book();
    $book->deleteFromDB($conn);
}
function handlePUT(mysqli $conn)
{
    parse_str(file_get_contents("php://input"), $data);
    $book = new Book();
    $book->update($conn, $data['id']);
    $book->setTitle($data['title']);
    $book->setAuthor($data['author']);
    $book->setDesc($data['desc']);
}
$methodType = $_SERVER['REQUEST_METHOD'];
$conn = Connection::startConnection();
switch ($methodType) {
    case "GET":
        handleGET($conn);
        break;
    case "POST":
        handlePOST($conn);
        break;
    case "DELETE":
        handleDELETE($conn);
        break;
    case "PUT":
        handlePUT($conn);
        break;
    default:
        die("nie obslugujemy");
}
CONNECTION::stopConnection($conn);
Пример #2
0
    header('Content-type: application/json');
}
function handlePUT()
{
    $conn = Connection::startConnection();
    parse_str(file_get_contents("php://input"), $data);
    header('Content-type: application/json');
    $book = new Book();
    $book->setName($data['name']);
    $book->setAuthor($data['author']);
    $book->setDesc($data['opis']);
    $book->updateBook($conn, $data['id']);
    Connection::stopConnecion($conn);
}
$methodType = $_SERVER['REQUEST_METHOD'];
switch ($methodType) {
    case "GET":
        handleGET();
        break;
    case "POST":
        handlePOST();
        break;
    case "DELETE":
        handleDELETE();
        break;
    case "PUT":
        handlePUT();
        break;
    default:
        die("Nie obsługujemy");
}