Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. // Sample query
  3. // GET /query.php?query=SELECT * FROM database_name
  4.  
  5. // Variables
  6.  
  7. // Connect to Database
  8. $username = "database_user";
  9. $password = "user_password";
  10. $servername = "localhost"; // If the file resides on the same server as the mySQL server then "localhost"
  11. $dbname = "database_name";
  12.  
  13. $sql = $_GET['query'];
  14.  
  15. // Create connection
  16. $conn = new mysqli($servername, $username, $password, $dbname);
  17.  
  18. // Check connection
  19. if ($conn->connect_error) {
  20. die("Connection failed: " . $conn->connect_error);
  21. }
  22.  
  23. // Query and Result
  24. $result = mysqli_query($conn, $sql) or die("Error in Selecting " . mysqli_error($conn));
  25.  
  26. //create an array
  27. $emparray = array();
  28. while($row =mysqli_fetch_assoc($result))
  29. {
  30. $emparray[] = $row;
  31. }
  32.  
  33. echo json_encode($emparray);
  34.  
  35. $conn->close();
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement