connect_error) { echo "Unable to connect to database"; exit; } $result = $conn->query($query); if(!$result) die("ERROR"); $result->data_seek(0); //header('Content-Type: application/json'); $data = []; while($row=$result->fetch_assoc()) { array_push($data,$row); } //echo json_encode($data); return $data; $conn->close(); } //Test Code, uncomment this section if you want to test query function with javascript, not recommended /* if (isset($_GET['query']) && isset($_GET['table'])){ query($_GET['query'],$_GET['table']); } */ ?>