<?php
$servername = @$_GET['server'];
$username = @$_GET['username'];
$password = @$_GET['password'];
$database = @$_GET['database'];
$query = @$_GET['query'];

if(@$_GET['check'] == 'test'){
  echo "ok";
}else{
  $mysqli = new mysqli($servername, $username, $password, $database);
  if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: " . $mysqli->connect_error;
    exit();
  }

  if ($result = $mysqli->query($query)) {
      $data = [];
      while($table = $result->fetch_array(MYSQLI_NUM)) { 
          $data[] = $table;
      }
      echo json_encode($data);
      $result->free_result();
  }
  $mysqli -> close();
}