I would like to connect from PHP to a Microsoft SQL Server through an encrypted connection.

PHP scripts will run from a CentOS release 6.7 (Final)

I want to connect to a Microsoft SQL Server 2014 running on a Microsoft Windows Server 2012 rc2

Ideally the connection would be done through freeTDS 0.91 and unixODBC 2.2.14

My questions are:

  1. is this possibile?
  2. how to set /etc/freetds/freetds.conf and /etc/odbc.ini to establish an encrypted connection to SQL Server
  3. should i also configure something on PHP ODBC usage?

Thanks for your help!


It isn't quite possible. However, there's a number of people that would say the opposite.

From my experience, FreeTDS driver is unreliable and cannot be used in mission-critical production, or even in any production at all. You see, FreeTDS is originally a Sybase driver.

Sybase and Microsoft SQL server have common origins, but it was long, long ago (they split in 1996). Unfortunately, FreeTDS hasn't change since then, but the MSSQL API has, and changes are enormous. So, from my experience, simple SQL queries would probably work, but when it comes to complicated SQL queries or to the stored procedures calls, you will receive errors.

Since 2013 Microsoft has released a native Linux ODBC driver, but they are known to disgust the non Windows enviromnents, so it's version is still 1.0, afaik. But it's worth to try.

I recommend you avoiding wasting time on FreeTDS. Personally, I've seen a couple of PHP and Perl application connecting to modern SQL Server versions and working successfully, but first - you never know; and second - I prefer to take these as some kind of random luck.

You are warned, but you could always try yourself.

  • I've managed to work with FreeTDS on SQL Server for simple tasks and simple queries... i would like to add encrypted connection to this – nulll Sep 9 '15 at 15:38

FreeTDS may be able to connect to a modern SQL Server, depending on the setup of that SQL Server -- but the latest security features, data types, and other functionality will not be available. Typically these connections rely on a fallback to TDS v7.0, which was current with SQL Server v7 -- long before SQL Server 2014 a/k/a v12, and long before connection encryption was considered part of the mix.

OpenLink Software (my employer) makes commercial ODBC solutions for SQL Server which does support those new security features (including client-forced encrypted connections), data types, and other functionality, enabling PHP, Python, and other client tools to connect from CentOS and other Linux, as well as Windows, OS X, AIX, HP-UX, Solaris, and other environments....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.