$rows = array(); while ($row = $result->fetch_assoc()) { $rows[] = $row; } /* $rows = mysqli_fetch_all($result, MYSQLI_ASSOC); */ $json = json_encode($rows); //This function returns the JSON representation of a value on success or FALSE on failure. } mysqli_free_result($result); //The mysqli_free_result() function frees the memory associated with the result $conn->close(); return $json; } function getSharedServerJSONData($sql) { $db = new interactDatabase(); $conn = $db->dbinteraction(); $arr = array(); $result = mysqli_query($conn, $sql); $totalrecords = mysqli_num_rows($result); while ($row = mysqli_fetch_assoc($result)) { $arr[] = $row; } $json = json_encode($arr, true); $conn->close(); return $json; } } $db = new InteractDatabase(); $db->dbinteraction();