SHARE
TWEET

Untitled

a guest Feb 21st, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top