Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. require 'Slim-3.10.0/vendor/autoload.php';
  3. $app = new Slim\App();
  4.  
  5. $app->get('/books', function ($request, $response, $args) {
  6. $con = mysqli_connect("localhost", "root", "", "books");
  7. $sth = mysqli_query($con, "SELECT * FROM book");
  8. $array = array(array());
  9. while($row = mysqli_fetch_row($sth)){
  10. $result[] = array('id'=>$row[0],
  11. 'title'=>$row[1],
  12. 'author'=>$row[2],
  13. 'published'=>$row[3]);}
  14. return $response->withJson($result);
  15. });
  16.  
  17. $app->get('/books/[{id}]', function ($request, $response, $args) {
  18. $con = mysqli_connect("localhost", "root", "", "books");
  19. $sth = mysqli_query($con, "SELECT * FROM book WHERE id=$args[id]");
  20. $array = array(array());
  21. while($row = mysqli_fetch_row($sth)){
  22. $result[] = array('id'=>$row[0],
  23. 'title'=>$row[1],
  24. 'author'=>$row[2],
  25. 'published'=>$row[3]);}
  26. return $response->withJson($result);
  27. });
  28.  
  29. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement