We also tried all available methods and found two working solutions handling unicode data in NVARCHAR fields. Unfortunately, the SQL Server Driver for PHP still has some bugs and is really hard to use as you have to convert NVARCHAR-like fields manually from UTF-16LE. There is support in Zend Framework 1.9.0, but I haven't looked at it yet.
Currently, the best way to access an SQL Server from PHP seems to be using COM and OLEDB:
$conn = new COM('ADODB.Connection', null, 65001);
$conn->Open('Provider=SQLNCLI;Server=SERVER;Database=DB;Uid=USER;Pwd=PASS');
$rs = $conn->Execute('SELECT nvarcharfield FROM sometable');
while (!$rs->EOF) {
echo $rs->Fields('nvarcharfield')->value, "\n";
$rs->MoveNext();
}
$rs->Close();
The "65001" indicates, that this component should work in UTF-8 mode, which is probably what you want. So all data in and out will be in UTF-8 encoding.
This would be great if prepared queries weren't so complex to program using COM, so you might want to have a look at ADOdb for PHP. The code then becomes just slightly different:
$conn = NewADOConnection('ado_mssql');
$conn->charPage = 65001;
$conn->Connect('Provider=SQLNCLI;Server=SERVER;Database=DB;Uid=USER;Pwd=PASS');
$conn->SetFetchMode('ADODB_FETCH_ASSOC');
$rs = $conn->Execute('SELECT nvarcharfield FROM sometable');
while (!$rs->EOF) {
echo $rs->fields['nvarcharfield'], "\n";
$rs->MoveNext();
}
$rs->Close();
Using ADOdb, prepared queries in ADOdb are much easier to write and understand.
If you have the new SQL Native Client from SQL Server 2008, you might want to replace the provider "SQLNCLI" with "SQLNCLI10".
As soon as I get some reputation, I'll add the links inline (only one hyperlink allowed for new users).
http://devzone.zend.com/article/4906-Zend-Framework-1.9.0-Released
http://msdn.microsoft.com/de-de/library/system.data.oledb.oledbcommand.prepare.aspx
http://adodb.sourceforge.net/
http://phplens.com/lens/adodb/docs-adodb.htm#prepare