How to set character encoding for MSSQL connection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Passiday
Forum Newbie
Posts: 1
Joined: Wed May 12, 2010 9:53 am

How to set character encoding for MSSQL connection

Post by Passiday »

Hello,

Could someone please advise how to set the character encoding for MSSQL connection, when using php on IIS?

The setup is as follows:
- Win 2003 server with IIS (6.0) and PHP (5.2.10) on it.
- MSSQL server 8.00.2039 SP4, default code page windows-1257

Standard php code like

$conn=mssql_connect('server','user','pwd') or die ("cannot connect<br>");
mssql_select_db("DB_Name");
$res=mssql_query("SELECT bla bla bla");

The problem is that data in $res are stored in windows-1257 encoding, thus garbling unicode characters that do not exist in this code page. How to force php to perform the conversation between php and sql server in utf-8? I know how to do it, when using php on Linux server (using freetds), but I could not find any advice online, how to do the same for php on Win PC.

Passiday
Brian Swan
Forum Newbie
Posts: 17
Joined: Thu Jan 14, 2010 11:56 am

Re: How to set character encoding for MSSQL connection

Post by Brian Swan »

This may be too late to help, but I'll post it anyway...

If you use the sqlsrv driver (which is produced by Microsoft), you might find some help here: http://msdn.microsoft.com/en-us/library ... L.90).aspx

Hope that helps.

-Brian
Post Reply