Advertisement
Guest User

Untitled

a guest
May 16th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1); error_reporting(-1);
  3.  
  4. $servername="localhost";
  5. $username="root";
  6. $password="root123";
  7. $dbname="KP1db";
  8.  
  9. $bateriaa=15;
  10. $czujnik_1=0;
  11. $czujnik_2=0;
  12.  
  13. try {
  14. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  15. // set the PDO error mode to exception
  16. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17. echo "Connected successfully";
  18. }
  19. catch(PDOException $e){
  20. echo "Connection failed: " . $e->getMessage();
  21. }
  22.  
  23. try {
  24. $sql = "SELECT * FROM dane2 ORDER BY lp DESC LIMIT 1";
  25. $row= $conn->query($sql);
  26. echo "Dane zostaly pobrane";
  27. }
  28. catch(PDOException $e){
  29. echo $sql . "<br>" . $e->getMessage();
  30. }
  31.  
  32. json_encode($row);
  33. ?>
  34.  
  35.  
  36.  
  37. ---JS
  38. setInterval(function(){
  39. &.getJSON("get.php",function(result){
  40. console.log(result);
  41. });
  42. }, 1/30 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement