requestDB.php 670 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. function query($query,$table){
  3. $conn = mysqli_connect("localhost","teabag","teabagpassword",$table);
  4. if($conn->connect_error)
  5. {
  6. echo "Unable to connect to database";
  7. exit;
  8. }
  9. $result = $conn->query($query);
  10. if(!$result) die("ERROR");
  11. $result->data_seek(0);
  12. //header('Content-Type: application/json');
  13. $data = [];
  14. while($row=$result->fetch_assoc())
  15. {
  16. array_push($data,$row);
  17. }
  18. //echo json_encode($data);
  19. return $data;
  20. $conn->close();
  21. }
  22. //Test Code, uncomment this section if you want to test query function with javascript, not recommended
  23. /*
  24. if (isset($_GET['query']) && isset($_GET['table'])){
  25. query($_GET['query'],$_GET['table']);
  26. }
  27. */
  28. ?>