Tag Archives: mssql

Installing MSSQL driver for PHP on Ubuntu

The driver used is FreeTDS, TDS stands for Tabular Data Stream which is an application layer protocol, used to transfer data between a database server and a client. It was initially developed by Sybase Inc. (that’s where the name of the package comes from, for those curious) and later by Microsoft for their relational SQL databases.

In most cases this should work:

sudo apt-get install php5-sybase freetds-common libsybdb5

but if it doesn’t, you probably need to change the TDS version that is in use by the driver. The configuration file is named freetds.conf, and should be in your /etc/ folder.

There are 2 ways for this:

  • Change the global settings, uncomment the global version and set it to the desired one, e.g.
    • tds version = 8.0
  • Or make a new server and set the version explicitly
    • [exampleServer]
      host = server.com
      port = 1433 (this is default MSSQL port)
      tds version = 7.0
If you picked the latter way, then just use exampleServer as the host, e.g.
mssql_connect("exampleServer\\SQLEXPRESS", "user", "password");

Ow, if it still isn’t working, then you have probably forgotten to allow remote connections on your server. From the start menu find and open “SQL Server Surface Area Configuration” then “Surface Area Configuration for Services and Connections”. Find your instance, expand the “Database Engine” tab, select “Remote Connections” and choose the “Using both TCP/IP and Named Pipes” option. After applying, you must restart your instance for the settings to take effect.

For info on TDS versions used in specific MSSQL version you can go here, or just use the direct link and download [MS-TDS].pdf and go to Appendix A. (or just use the newest version, think it’s 8.0 at the moment, it should work fine)

Tagged , , , ,