For some project, I’ve build a webshop in PHP, with a MS SQL 2005 database. I hear you thinking, why didn’t you use some MySQL of PostgreSQL database? Well, the MS SQL database is used by SAP to store product information etcetera, so another database wasn’t an option.
So, no problems, just installed php5-sybase on my Debian box and off we go with mssql_connect(), and voila, a nice connection with the MS SQL server. So far so good.
Now, the webshop was near finished, and I moved the shop from my Debian box to the MS Windows Server 2003 box where the MS SQL server was running, together with IIS and PHP for Windows. As soon as I fired up the shop, PHP errors:
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. (severity 16)
Ouch. What could that be? I discovered soon enough that I’m not the only one with this problem, according to PHP.net. Rewriting all querys was no option as this would be too much work, without a success guarantee. So, we’ve set up a virtual machine on the Windows box using VirtualBox, and I installed Debian, together with apache2, php5 and the php5-sybase module. Tested it, but what the… Still unicode errors!
The solution was fairly simple. By default, the tds protocol version is set to 4.0 in Debian. So, just edit /etc/freetds/freetds.conf and set the protocol version to 8.0 under [global]. Restart Apache, and voila… No more troubles.