First, we're using MS SQL Server 2005 to store our information, so the text field(s) to be holding Unicode characters need to have a "N" (national) data type. For this case, I used "ntext". (As an aside, I believe MS is/has deprecated this data type and now wants nvarchar(max) or something equivalent.)
This allowed the front end client to enter Chinese characters into the database.
Then back to serving pages, I immediately ran into problems retrieving the selection set through PHP:
Warning: mssql_query() [function.mssql-query]: message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in...
I determined that our web server was using a FreeTDS library and updated freetds.conf to use tds version 8.0 instead of 4.2 for global settings. (The file on our system was located in /etc/freetds/)
With that done, I could at least get the text out of the database, but PHP was still treating / serving it as single-byte encoded. The final settings tweak was to set the mssql character set. Before establishing any connection. I do this, so:
ini_set('mssql.charset', 'UTF-8');
This finally establishes a flow of characters from database to browser that are Unicode encoded.
2 comments:
Glad it was helpful!
I'm fairly certain that 7.2 is the highest FreeTDS protocol version.
Post a Comment