Skip to content

Instantly share code, notes, and snippets.

@arwankhoiruddin
Created December 2, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arwankhoiruddin/62bb8b8d31ef1d1475aaa3ce4c7eaff0 to your computer and use it in GitHub Desktop.
Save arwankhoiruddin/62bb8b8d31ef1d1475aaa3ce4c7eaff0 to your computer and use it in GitHub Desktop.
<?php
// this is unsafe way to get JSON from your MySQL... but it is fun... hahaha
$servername = "myhost";
$username = "myusername";
$password = "mypassword";
$dbname = "mydb";
$sql = $_GET['sql'];
$con=mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result=mysqli_query($con,$sql);
$arr = [];
while($row = mysqli_fetch_assoc($result)){
foreach($row as $key => $value){
$arr[$key] = $value;
}
}
echo json_encode($arr);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment