Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2. header('Content-type: application/json');
  3.  
  4. $servername = "localhost";
  5. $username = "username";
  6. $password = "secret";
  7. $dbname = "arduinoData";
  8.  
  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. }
  15.  
  16. $sql = "SELECT timeStamp, out_temperature, out_humidity FROM sensorLog ORDER BY timeStamp DESC LIMIT 1";
  17. $result = $conn->query($sql);
  18.  
  19. if ($result->num_rows > 0) {
  20. // output data of each row
  21. while($row = $result->fetch_assoc()) {
  22. echo "<br>Time: ". $row["timeStamp"]. "<br>Temperature: ". $row["out_temperature"]. "<br>Humidity: " . $row["out_humidity"] . "<$
  23. }
  24. } else {
  25. echo "0 results";
  26. }
  27.  
  28. $conn->close();
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement