MS SQL problem with Unicode

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

MS SQL problem with Unicode

Post by Ree »

I am having a serious problem retrieving unicode data from nvarchar and ntext columns. Basically, I entered some data manually using MS SQL Server Management Studio and then tried to retrieve (I use PDO with ODBC) and display it in an html page. The problem is that the unicode characters come up as ?'s on the page.

Before you mention, yes, the html has utf-8 charset set.

I remember having a similar problem with MySQL and it could easily solved by executing "SET NAMES 'utf8'" before querying the db. This obviously doesn't work with MS SQL.

Anyone could help me solving this?

Update: Actually, I found that MS SQL uses a different Unicode encoding UCS-2. So a conversion is required from UCS-2 to UTF-8. I thought the function mb_convert_encoding() was god sent to me but guess what? Yeah, it doesn't help at all. I am wondering maybe the data get's damaged when it 'travels' through PDO?
Post Reply