PHP and FreeTDS with MSSql: wrong charset

I recently ran into a nasty issue: when accessing a MSSql database from Linux with PHP and through FreeTDS I had some characters displayed wrong, like ° or similar. Everything was working fine, queries were ok, but for example in Adminer i saw weird characters in replacement of the good ones. After tweaking a bit with FreeTDS config I also had other errors, like

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

when displaying table structure.

I tried several config changes, like setting




in php.ini, but all were irrelevant.

Also changing

client charset = UTF-8

in freetds.conf didn’t change anything.

Turned out being the tds version parameter of freetds.conf:  I had set it to 11.0 which is the latest allowed by my FreeTDS version, but was misbehaving with those characters. Setting it to 8.0 solved the problem! So in the end this is the configuration I used in /etc/freetds/freetds.conf:


host =
port = 49160
tds version = 8.0
client charset = UTF-8

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.

Solve : *
8 + 30 =

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.