后端 JSON 响应


Backend JSON response

我创建了一个CMS并在localhost中对其进行了测试,并读取了所有json响应。但是,当我将代码放入实时服务器时,我仍然可以插入查看编辑数据,但我无法读取任何 json 响应。这是一个艰巨的部分,因为我的安卓应用程序需要它们。

这是我的代码。

<?php
include ("../includes/connect.php");
$string = "";
$newString = "";
$get_posts = "select * from last_game";
$run_posts = mysqli_query($con, $get_posts);
$posts_array = array();
while ($posts_row = mysqli_fetch_array($run_posts))
{
  $row_array['id'] = $posts_row['id'];
  $row_array['game'] = $posts_row['game'];
  $row_array['date'] = $posts_row['date'];
  array_push($posts_array, $row_array);
}
$string = json_encode($posts_array, JSON_UNESCAPED_UNICODE);
echo $string;
?>

我得到的错误是

Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 
'JSON_UNESCAPED_UNICODE' in /var/www/vhosts/theo-
 android.co.uk/httpdocs/manudb/android/last_game_json.php on line 26
Warning: json_encode() expects parameter 2 to be long, string given in    
/var/www/vhosts/theo-
android.co.uk/httpdocs/manudb/android/last_game_json.php on line 26

可能是 php 版本出了问题吗?

有什么想法吗?

谢谢。

可能您的MySQL连接在实时服务器上需要不同的凭据:检查您的connect.php以确保MySQL主机/用户/密码和数据库名称正确。

您可以通过手动将浏览器指向远程服务器并查看发生了什么来检查服务器响应,也许您应该使用以下内容启用调试: error_reporting(E_ALL); ini_set("display_errors", 1);

重要提示:请记住在投入生产时删除这些行!