I can't seem to get data from MSSQL encoded as UTF-8 using FreeTDS extension.
Connecting:
ini_set('mssql.charset', 'UTF-8');
$this->_resource = mssql_connect($config['servername'], $config['username'], $config['password']);
I have no ability to use any other extension.
I've tried creating ~/.freetds.conf
[global]
client charset = UTF-8
I've tried passing parameters to php:
php -d mssql.charset="UTF-8" index.php
Data is still not in UTF-8.
php -i
mssql
MSSQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Library version => FreeTDS
Directive => Local Value => Master Value
mssql.allow_persistent => On => On
mssql.batchsize => 0 => 0
mssql.charset => no value => no value
mssql.compatability_mode => Off => Off
mssql.connect_timeout => 5 => 5
mssql.datetimeconvert => On => On
mssql.max_links => Unlimited => Unlimited
mssql.max_persistent => Unlimited => Unlimited
Ideas?
MSSQL and UTF-8 are quite a pain in the ... sometimes. I had to convert it manually. The problem: MSSQL doesn't actually know and support UTF-8.
Convert from database value to UTF-8:
Converting from UTF-8 to database value:
Fortunately I was using Doctrine so all I had was to create a custom StringType implementation.
You should change your TDS version based on what version of SQL server your using. Check out the installation guide for details.
http://www.freetds.org/userguide/choosingtdsprotocol.htm
You can also solve this issue by adding CharacterSet UTF-8 in the $connectionInfo before connecting to the DB.
Worked fine NO additional encoding needed.
If you use freeTDS, you should change below lines on
/etc/freetds/freetds.conf
:To this:
and finally add this line:
** clinet charset is in global [scope]
In your queries, you should use N character. like this:
It seem version 7.0 or great is required. iconv() also seems to work well, but is tedious.
I had this problem and it solved by adding this line to my php script before connecting to MSSQL Server: