2016-07-11 98 views
1

從數據庫中進行SELECT查詢時,有時會在文本字段中獲得空值。這似乎是隨機的,但通常在我更新數據庫後,這個問題似乎隨之而來。以下是我的代碼:PHP json_encode SOMETIMES從數據庫查詢返回「null」作爲值

require_once('database.php'); 

$sql = "SELECT stories.id, authors.name AS author, authors.dates AS dates, authors.life AS life, stories.title AS title, stories.text AS text, stories.summary AS summary, stories.reading_time AS time, stories.cost AS cost, stories.file_name AS story_filename, category.name AS category 
FROM stories 
INNER JOIN category ON stories.category_id = category.id 
INNER JOIN authors ON stories.author_id = authors.id"; 

if ($result = mysqli_query($con, $sql)) { 
$resultArray = array(); 
$tempArray = array(); 

while($row = $result->fetch_object()) { 
$tempArray = $row; 
array_push($resultArray, $tempArray); 
} 
echo json_encode($resultArray, JSON_PRETTY_PRINT); 
} 
mysqli_close($con); 

錯誤發生在文本字段上。它來作爲

text = "<null>"; 

其他領域都很好。

我很感激這方面的幫助!謝謝

+1

檢查瀏覽器?最有可能的瀏覽器''混合它就像標籤 – Ghost

+0

感謝您的響應,但問題是對使用此代碼連接到數據庫的應用程序的JSON響應。該應用程序正在使用Swift 2.0,並且有時(在對數據庫進行任何更新後)從此代碼檢索到的json具有值。 – arthurvillar

回答

0

我有同樣的問題。 我的解決方案是將數據庫中的文本字段屬性從utf8_general_ci更改爲asci_bin。

關於