Search code examples
phpsql-serverutf-8nvarchar

How to echo nvarchar instead of "??"


I have data in SQL Server with nvarchar, one example "გიორგი შონია", but when I try to echo this in PHP I get "?????? ?????".

I have tried 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 />";
}

Solution

  • I found answer, for them who'll face this problem we can make add "CharacterSet" => "UTF-8" into conn array for example I had :

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

    and I changed to :

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