The accepted answer seems to do the job; yes, you can encode it to base64 and then decode it again, but then all applications using this remote database must change and support the fields that base64 will encode. I believe that if there is a remote MS SQL Server database, there may be another application (or applications) that can use it, so the application should also be modified to support both simple and base64 encoding. And you will also have to process both plain text and base64 text.
I searched a bit and I found how to send UNICODE text to MS SQL Server using MS SQL and PHP commands to convert UNICODE bytes to HEX numbers.
If you go to the PHP documentation for mssql_fetch_array ( http://php.net/manual/ru/function.mssql-fetch-array.php#80076 ), you will see comments a good solution that converts text to UNICODE HEX values and then sends this HEX data directly to MS SQL Server as follows:
Convert Unicode text to HEX data
// sending data to database $utf8 = 'Δοκιμή με unicode → Test with Unicode'; // some Greek text for example $ucs2 = iconv('UTF-8', 'UCS-2LE', $utf8); // converting UCS-2 string into "binary" hexadecimal form $arr = unpack('H*hex', $ucs2); $hex = "0x{$arr['hex']}"; // IMPORTANT! // please note that value must be passed without apostrophes // it should be "... values(0x0123456789ABCEF) ...", not "... values('0x0123456789ABCEF') ..." mssql_query("INSERT INTO mytable (myfield) VALUES ({$hex})", $link);
Now all the text is actually stored in the NVARCHAR database NVARCHAR correctly, like UNICODE, and all you need to do to send and save it as plain text and not encode.
To get this text, you need to ask MS SQL Server to send back the UNICODE encoded text as follows:
Unicode text extraction from MS SQL Server
// retrieving data from database // IMPORTANT! // please note that "varbinary" expects number of bytes // in this example it must be 200 (bytes), while size of field is 100 (UCS-2 chars) // myfield is of 50 length, so I set VARBINARY to 100 $result = mssql_query("SELECT CONVERT(VARBINARY(100), myfield) AS myfield FROM mytable", $link); while (($row = mssql_fetch_array($result, MSSQL_BOTH))) { // we get data in UCS-2 // I use UTF-8 in my project, so I encode it back echo '1. '.iconv('UCS-2LE', 'UTF-8', $row['myfield'])).PHP_EOL; // or you can even use mb_convert_encoding to convert from UCS-2LE to UTF-8 echo '2. '.mb_convert_encoding($row['myfield'], 'UTF-8', 'UCS-2LE').PHP_EOL; }
MS SQL table with UNICODE data after INSERT

Output result using a PHP page to display values

I'm not sure you can get to my test page here, but you can try to see the results: http://dbg.deve.wiznet.gr/php56/mssql/test1.php