5

I'm using freetds + unixODBC + php pdo_odbc to access MSSQL Server 2012

+ CentOS 7 x86_64
+ freetds version 0.95.19
+ unixODBC version 2.3.4
+ php version 5.6.14

When retreiving results from SQL Server in UTF-8 I get NULL characters (\u0000 in JSON) in long strings, which, when htmlencoded by JavaScript becomes "�". The only thing I've found in the internet is this post in FreeTDS mailing list.

By the way, Microsoft ODBC Driver 11 for SQL Server on Linux works fine in this case, but has some other issues I could not solve.

UPD: Configs

/etc/freetds.conf

[global]
  text size = 2147483647
[ibmMSSQL]
  host = ibm.sevkav.local
  port = 49927
  tds version = 7.3
  client charset = UTF-8

/etc/odbc.ini

[ODBC Data Sources]

[ibmMSSQL]
Description = MSSQL Server
Trace = No
Servername = ibmMSSQL
Database = MRS

[ibmMSSQLnative]
Driver = SQL Server Native Client 11.0
Description = Test MS Driver
Trace = no
Server = ibm.sevkav.local,49927\EAIS_MIRROR
Database = MRS

[Default]
Driver = FreeTDS

/etc/odbcinst.ini

[ODBC]
#DEBUG=1
#TraceFile=/tmp/sqltrace.log
#Trace=Yes

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbcw.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbcw.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1

[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/libmyodbc5.so
Setup=/usr/lib/libodbcmyS.so
Driver64=/usr/lib64/libmyodbc5.so
Setup64=/usr/lib64/libodbcmyS.so
FileUsage=1

[FreeTDS]
Description=ODBC for FreeTDS
Driver64=/usr/lib64/libtdsodbc.so.0
FileUsage=1
client charset = utf-8

[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/usr/lib64/libsqlncli-11.0.so.1790.0
Threading=1
UsageCount=1
Mizax
  • 86
  • 5
  • So first, I don't believe you can use "client charset" in `odbcinst.ini` - it is probably just being ignored. Can you try adding `Charset=UTF-8` to your DSN definition in odbc.ini? – FlipperPA Nov 03 '15 at 19:13
  • Yes, you're right, "client charset" does not affect it at all, changed it to `Charset=UTF-8` and NULL char is still there. I have to mention that I've compilled unixODBC with `./configure --enable-gui=no --enable-drivers=no --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --libdir=/usr/lib64 --prefix=/usr --sysconfigdir=/etc` for native driver from MS. – Mizax Nov 05 '15 at 11:42

0 Answers0