0
我需要簡單的Web服務來從本地數據庫獲取數據,但是當我將文件從測試服務器移動到實際服務器時,我只是收到空白頁左上角。 我的PHP代碼非常簡單:我的服務器返回空白頁在角落'null'
<?php
// Include config
require_once 'config/db.php';
$sql = new db();
$conn = $sql->connect();
$task = isset($_GET['task']) ? mysql_real_escape_string($_GET['task']) : "";
if(!empty($task))
{
if($task === "totals")
{
$qur = mysql_query("working query - no problem here;");
$result =array();
while($r = mysql_fetch_array($qur))
{
extract($r);
$result[] = array("total_value" => $total_value, 'orders_date' => $orders_date, 'number_of_orders' => $number_of_orders);
}
$json = $result;
}
}
@mysql_close($conn);
/* Output header */
header('Content-type: application/json');
echo json_encode($json, JSON_PRETTY_PRINT);
?>
這裏是db.php中代碼:
<?php
class db
{
// Properties
private $dbhost = 'ip-address';
private $dbuser = 'xxx';
private $dbpass = 'yyy';
private $dbname = 'zzz';
// Connect
public function connect()
{
$conn = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db($this->dbname, $conn);
}
}
?>
mysql函數折舊。改用mysqli函數。還查找參數化查詢以避免SQL注入。 –
我認爲這行'''echo json_encode ...'''什麼是生成頁面上的「null」。當你查看源代碼時,你看到了這一切嗎? –
打開錯誤報告並查看正在生成的錯誤以及代碼中的位置。 –