Friday, December 16, 2011

PHP, MS SQL Server, sqlsrv_connect() "CharacterSet"=>"UTF-8" is recommended in $connectionInfo if you got character encoding problem like me.

If you're like me that is using MS SQL Server 2008 R2 and going to use sqlsrv driver, now I'm using php_sqlsrv_53_ts_vc9.dll, for PHP and then facing the problem of character encoding problem on the browser, I found out someone recommended putting "CharacterSet"=>"UTF-8" in $connectionInfo in sqlsrv_connect(). And it works like a charm for me.

I didn't even need to convert the datatype from varchar to nvarchar to work with, though many posts on the web recommended to make such a change; I'm not sure yet, since I just tested with "select" statement, I'll test with "update" and "insert" later.

Anyway, by now, 2008 r2 works just fine with adding this simple option, "CharacterSet"=>"UTF-8" , in $connectionInfo of sqlsrv_connect() for select statement.

Updated:3/3/2012
I've used this on stored-procedure, select statement, insert, update and delete without any changes from the database which is my primary objective. And now, I just put it on Amazon EC2 server with SQL Express 2008 as it is also free of charge for the first year. So good!

1 comment:

gyunee said...

thank you so much..

I resovle my recent problem phpbb3(3.0.10) and php 5.3.9 in IIs 7.5

simply resolved...

thanks again..