Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'Slim-3.10.0/vendor/autoload.php';
- $app = new Slim\App();
- $app->get('/books', function ($request, $response, $args) {
- $con = mysqli_connect("localhost", "root", "", "books");
- $sth = mysqli_query($con, "SELECT * FROM book");
- $array = array(array());
- while($row = mysqli_fetch_row($sth)){
- $result[] = array('id'=>$row[0],
- 'title'=>$row[1],
- 'author'=>$row[2],
- 'published'=>$row[3]);}
- return $response->withJson($result);
- });
- $app->get('/books/[{id}]', function ($request, $response, $args) {
- $con = mysqli_connect("localhost", "root", "", "books");
- $sth = mysqli_query($con, "SELECT * FROM book WHERE id=$args[id]");
- $array = array(array());
- while($row = mysqli_fetch_row($sth)){
- $result[] = array('id'=>$row[0],
- 'title'=>$row[1],
- 'author'=>$row[2],
- 'published'=>$row[3]);}
- return $response->withJson($result);
- });
- $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement