Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. //setting header to json
  3. header('Content-Type: application/json');
  4.  
  5. //database
  6. define('DB_HOST', 'localhost');
  7. define('DB_USERNAME', 'admin');
  8. define('DB_PASSWORD', 'eass');
  9. define('DB_NAME', 'EMMA');
  10.  
  11. //get connection
  12. $mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
  13.  
  14. if(!$mysqli){
  15.   die("Connection failed: " . $mysqli->error);
  16. }
  17.  
  18. //query to get data from the table
  19. $query = sprintf("SELECT ts, Gesamtwirkleistung, Gesamtscheinleistung, Gesamtblindleistung FROM Gleichrichter_Mix");
  20.  
  21. //execute query
  22. $result = $mysqli->query($query);
  23.  
  24. //loop through the returned data
  25. $data = array();
  26. foreach ($result as $row) {
  27.   $data[] = $row;
  28. }
  29.  
  30. //free memory associated with result
  31. $result->close();
  32.  
  33. //close connection
  34. $mysqli->close();
  35.  
  36. //now print the data
  37. print json_encode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement