Php脚本执行但它不显示任何内容

时间:2016-11-08 18:45:12

标签: php android sql-server json

我有一个php acript,其目标是以json格式从数据库中获取数据,以便在Android应用程序上显示所述数据。

我在服务器上运行脚本,但它不返回任何内容,没有文本,没有任何内容,只是一个空白页面。我甚至在看了很多文件之后都不知道为什么。

剧本:

    <?php

$serverName = "mssql3.gear.host";

/* Get UID and PWD from application-specific files.  */
$uid = '-----------';
$pwd = '-----------';
$connectionInfo = array( "UID"=>$uid,
                         "PWD"=>$pwd,
                         "Database"=>"programaplo");

/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Unable to connect.</br>";
     die( print_r( sqlsrv_errors(), true));
}

echo 'Connected successfully';

$tsql = "SELECT * FROM Obras";
$stmt = sqlsrv_query($conn, $tsql);

if( $stmt === false ) {
     echo "Error in executing query.</br>";
     die( print_r( sqlsrv_errors(), true));
}

$json = array();

do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
     $json[] = $row;
   }
} while ( sqlsrv_next_result($stmt) );

/* Run the tabular results through json_encode() */
/* And ensure numbers don't get cast to trings */
print json_encode($json,<code> JSON_NUMERIC_CHECK</code>);
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);

?>

由于

1 个答案:

答案 0 :(得分:0)

这条线似乎是罪魁祸首 - 它让你解析错误:

print json_encode($json,<code> JSON_NUMERIC_CHECK</code>);

将其更改为:

print json_encode($json, JSON_NUMERIC_CHECK);