2014-04-14 4 views
0

안녕을 사용하여 UTF-8 JSON 데이터를 검색MSSQL 내가 PHP를 사용하여 내 데이터베이스에서 아랍어 데이터를 검색하려고하지만 내가 가진 모든 질문 마크가 .. 데이터가 데이터베이스에서 잘 저장하고 열 유형이 NVARCHAR입니다 PHP

db_connect.php :

나는 내 PHP는이 코드 ini_set('mssql.charset', 'UTF-8');를 넣어하지만 여전히 여기

내 코드의 샘플이 작동하지 않는 시도

<?php 

ini_set('mssql.charset', 'UTF-8'); 

$link=mssql_connect('SQL*******', 'username', 'password'); 

?> 

get_about.php을

012
<?php 

     include_once './db_connect.php'; 
     $sql ="SELECT * FROM About"; 
     $select = mssql_query($sql); 

     if ($select) { 
      while ($list = mssql_fetch_array($select)){ 
       $output = $list; 
      } 
      print json_encode($output); 
     } else { 
      print json_encode('fail select'); 
     } 



?> 
+0

가 잘못된 데이터를 완전히인가 봅니다 3,516,? (JSON으로 변환하지 않고) –

+0

이 답변은 당신에게 가치있을 수 있습니다 : http://stackoverflow.com/a/13377935/647621 – bigmike7801

+0

@ mark.sagikazar 심지어 json에 enconding하지 않고도 여전히 아랍어 데이터를 검색 할 때 의문점이 있습니다 – FinalDark

답변

0

<?php 
$user = "user"; 
$pass = "Password"; 

//11.0 for SQL 2012,2014 

$dsn = "Driver=SQL Server Native Client 11.0;Server=server.com;Port=1433;Database=database;"; 
$cx = odbc_connect($dsn,$user,$pass); 

// Get the error message 

if($cx === false) { 
    throw new ErrorExcpetion(odbc_errormsg()); 
}; 
$resultset=odbc_exec($cx, "SELECT * FROM Table"); 


$json = array(); 

do { 
    while ($row = odbc_fetch_array($resultset)) { 
    $json[] = $row; 
    } 
} while (odbc_next_result($resultset)); 

/* Run the tabular results through json_encode() */ 
/* And ensure numbers don't get cast to trings */ 
echo json_encode($json); 

odbc_close($cx); 

?>