如何回显nvarchar而不是“ ??”

时间:2019-08-25 21:16:51

标签: php sql-server utf-8 nvarchar

我在使用nvarchar的SQL Server中具有数据,例如“გიორგიგიორგი”,但是当我尝试在PHP中回显此数据时,我得到“ ?????? ?????”。

我尝试过header('content-type: text/html; charset=utf-8');

$sql = "SELECT * FROM user_login";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
     echo 'ras';
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
      echo $row['user_username'].", ".$row['user_fullname']."<br />";
}

1 个答案:

答案 0 :(得分:1)

我找到了答案,对于那些会遇到此问题的人,我们可以将"CharacterSet" => "UTF-8“添加到conn数组中,例如我拥有的

$connectionInfo = array( "Database"=>"xxx", "UID"=>"xxx", "PWD"=>"xxxx");

然后我改为:

$connectionInfo = array( "Database"=>"xxx", "UID"=>"xxx", "PWD"=>"xxxx","CharacterSet" => "UTF-8");