Journal & Notebook

PHP MSSQL Connections

5 years agoApril 17th, 2013

Let's pretend you want to connect to a MSSQL server to pull/sync data out of an application you did not write, and you use a PHP framework for your web app. The framework provides an sqlsrv driver to connect to Sybase and MSSQL servers. However, you will need to make the following tweaks to your system in order to get a valid connection.

First install the sybase package for php (Debian/Ubuntu):

$ sudo apt-get install php5-sybase

While this will work for most tables, it will break on any ntext columns.

Next you will need to edit /etc/freetds/freetds.conf

Add these lines under [global]:

tds version = 8.0
client charset = UTF-8

This will enable support for ntext/nvarchar columns. Otherwise you'll see a '4004' error when you try to connect to a table.