Guest User

Untitled

a guest
Dec 2nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. // this is unsafe way to get JSON from your MySQL... but it is fun... hahaha
  4.  
  5. $servername = "myhost";
  6. $username = "myusername";
  7. $password = "mypassword";
  8. $dbname = "mydb";
  9.  
  10. $sql = $_GET['sql'];
  11.  
  12. $con=mysqli_connect($servername, $username, $password, $dbname);
  13. // Check connection
  14. if (mysqli_connect_errno())
  15. {
  16. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  17. }
  18.  
  19. $result=mysqli_query($con,$sql);
  20.  
  21. $arr = [];
  22. while($row = mysqli_fetch_assoc($result)){
  23. foreach($row as $key => $value){
  24. $arr[$key] = $value;
  25. }
  26. }
  27. echo json_encode($arr);
  28. ?>
Add Comment
Please, Sign In to add comment