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

</p>
<p>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</p>
<p>

when displaying table structure.

I tried several config changes, like setting

mssql.charset

or

default_charset

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:

 

</p>
<p>[servername]<br />
host = 192.168.1.5<br />
port = 49160<br />
tds version = 8.0<br />
server = INSTANCENAME\DBNAME<br />
client charset = UTF-8</p>
<p>

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Solve : *
25 × 12 =


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