2016-04-24 110 views
-1

我已经创建了一个CMS,并在localhost中进行了测试,并读取了所有json响应。然而,当我把代码放在一个活的服务器上,我仍然可以插入,视图编辑数据,但我无法读取任何json响应。而这是一个非常重要的部分,因为我需要他们为我的android应用程序。后端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版本?

任何想法?

谢谢。

+0

我们不能帮你没有看到你得到的错误...检查浏览器的开发者控制台的JS错误或服务器的PHP错误(如果他们被设置为不显示) –

+0

删除JSON_UNESCAPED_UNICODE常量 –

+0

是!!!它现在正在工作!:)谢谢 – Theo

回答

1

可能是你的MySQL连接需要现场服务器上的不同凭据: 检查connect.php,以确保MySQL的主机/用户/密码和数据库名称是否正确。

你可以通过你的浏览器中手动指向远程服务器检查什么服务器响应,看看发生了什么,也许你应该启用调试的东西,如: error_reporting(E_ALL); ini_set("display_errors", 1);

重要:记得去掉那些线在生产中去的时候!

+0

把你建议的代码行后,我得到这个错误。 – Theo

+0

注意:使用未定义的常量JSON_UNESCAPED_UNICODE - 假设'JSON_UNESCAPED_UNICODE'在/var/www/vhosts/theo-android.co.uk/httpdocs/manudb/android/last_game_json.php在第26行 警告:json_encode()期望参数2长,字符串在/var/www/vhosts/theo-android.co.uk/httpdocs/manudb/android/last_game_json.php在26行 – Theo