To write Unicode (nvarchar) to SQL2000/2005 use PHP
用PHP在SQL Server 存取Unicode資料
----------------------------------------------
Let's assume, we have following data table, that allows us to store unicode values (using UCS-2 encoding):
create table mytable (
myfield nvarchar (100) null
);
Below is the code to work with:
<?php
$link = mssql_connect('dbhost', 'username', 'password');
mssql_select_db('database', $link);
$utf8 = 'some unicode UTF-8 data'; $ucs2 = iconv('UTF-8', 'UCS-2LE', $utf8);
$arr = unpack('H*hex', $ucs2);
$hex = "0x{$arr['hex']}";
mssql_query("insert into mytable (myfield) values ({$hex})", $link);
$result = mssql_query("select convert(varbinary(200), myfield) from mytable", $link);
while (($row = mssql_fetch_array($result, MSSQL_BOTH)))
{
echo(iconv('UCS-2LE', 'UTF-8', $row['myfield']));
}
mssql_free_result($result);
mssql_close($link);
?>