Advertisement
Avishka_Perera

My Web Service Declaration

Mar 19th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. if((isset($_REQUEST["ID"]))&&(isset($_REQUEST["Status"]))){
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "arduino_test";
  7.  
  8. $jsonarray= array('Status' => false,'Message'=>"Empty" );
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. $jsonarray= array('Status' => false,'Message'=>"Database Not Connected" );
  15. //echo json_encode($jsonarray);
  16.  
  17. }
  18. else{
  19. $jsonarray= array('Status'=>True,'Message'=>"Database connected" );
  20.  
  21. $sql = "SELECT * FROM `lights` WHERE ID=".$_REQUEST["ID"]."";
  22.  
  23.  
  24.  
  25.  
  26. if (($result = $conn->query($sql)) !== FALSE)
  27. {
  28. echo "query success";
  29. $data = array(); //empty array
  30.  
  31. while($row = $result->fetch_assoc())
  32. {
  33. $jsonarray1[] = $row; //store each row in $data
  34. }
  35.  
  36. //echo json_encode($jsonarray);
  37. echo json_encode($jsonarray1);
  38. }
  39. else
  40. {
  41. echo "query failure";
  42. echo "Error: " . $sql . "<br>" . $conn->error;
  43. }
  44.  
  45. //echo json_encode($jsonarray);
  46.  
  47.  
  48. }
  49.  
  50. }
  51.  
  52.  
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement