Sebuahhobi98

api

Feb 23rd, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. header('Content-Type: application/json');
  3. $method = $_SERVER['REQUEST_METHOD'];
  4. $request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
  5. //$input = json_decode(file_get_contents('php://input'),true);
  6.  
  7. $link = mysqli_connect('localhost', 'root', '', 'al_quran');
  8. mysqli_set_charset($link,'utf8');
  9.  
  10. $data = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));
  11. //$id = array_shift($request)+0;
  12. $id=$_GET['text'];
  13. if (strcmp($data, 'data') ==0) {
  14. switch ($method) {
  15. case 'GET':
  16. $sql = "select * from al_quran_indonesia where text like '%".$id."%'";break;
  17. }
  18. $result = mysqli_query($link,$sql);
  19.  
  20. if (!$result) {
  21. http_response_code(404);
  22. die(mysqli_error());
  23. }
  24.  
  25. if ($method == 'GET') {
  26. $hasil=array();
  27. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
  28. $hasil[]=$row;
  29. }
  30. $hasil1 = array('status' => true, 'message' => 'Data show succes', 'data' => $hasil);
  31. echo json_encode($hasil1);
  32.  
  33. } /*elseif ($method == 'POST') {
  34. echo mysqli_insert_id($link);
  35. } */else {
  36. echo mysqli_affected_rows($link);
  37. }
  38. }else{
  39. $hasil1 = array('status' => false, 'message' => 'Access Denied');
  40. echo json_encode($hasil1);
  41. }
  42.  
  43. mysqli_close($link);
  44. ?>
Add Comment
Please, Sign In to add comment