1

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 />";
}
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    Possible duplicate of [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – miken32 Aug 25 '19 at 22:14
  • @miken32 I was going to use that link to close it with earlier. However and I have always found this to be a bit odd that, the Q&A doesn't mention anything about MSSQL, only MySQL. – Funk Forty Niner Aug 25 '19 at 22:22
  • Yeah it would be nice to have a more database-agnostic answer in there, because the same things apply to all databases even if the specific code is different. @FunkFortyNiner – miken32 Aug 25 '19 at 22:26
  • @miken32 It would be nice for sure. – Funk Forty Niner Aug 25 '19 at 22:29

1 Answers1

1

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");