2017-07-31 78 views
1
Array 
(
    [0] => Array 
     (
      [acctcode] => 631 
      [description] => Blood Transfussion Set, Blood Transfusion Set- ADULT 
      [pchrgqty] => 1.00 
      [pchrgup] => 17.00 
      [pcchrgamt] => 17.00 
      [patlast] => GUADA�A 
      [patfirst] => FRITZIE ELINE 
      [patmiddle] => DAYTEC 
      [patsuffix] => 
     ) 

) 

在PHP上述陣列的print_r($result);現在這個陣列將被如下json_encoded結果:Mssql中結果json_encode不返回任何東西的PHP PDO

echo json_encode($result, JSON_UNESCAPED_UNICODE); 

我編碼本,因爲它是AJAX請求。現在在回聲部分它不返回任何東西。我不知道爲什麼發生這種情況,但我的猜測是因爲 「Ñ」這是在[patlast] => GUADA�A,並顯示爲。我在MSSQL DATABASE中選擇了此結果集。

如何在MSSQL中處理這個結果集並能夠返回正確的數據。

+1

你試過UTF -8編碼嗎? – Difster

+0

我曾嘗試在標題中添加UTF-8,但它沒有解決問題,我做了更多的挖掘,並找到了最好的解決方案,下面的功勞歸於科莫 – Martin

回答

1

我已經找到了我的項目在here

最好的解決方案使用下面的代碼:

// Create an empty array for the encoded resultset 

$rows = array(); 

// Loop over the db resultset and put encoded values into $rows 

while($row = mysql_fetch_assoc($result)) { 
    $rows[] = array_map('utf8_encode', $row); 
} 

// Output $rows 

echo json_encode($rows); 

答案被賦予我的用戶凱莫

+1

而且您可以將自己的解決方案標記爲已解決! :) – Difster