Connecting MSSQL Server with Zend Framework on Linux

Few days ago we completed a project which used Zend framework and the database was MS Sql Server 2005. We had tough time deploying the project on Linux. Initially we started with Ubuntu but in Ubuntu php-mssql package is missing. We tried to compile it but didnt work. Then we decided to use Fedora which has php-mssql package. So the following steps should work for any distro with php-mssql package in it.

With PHP already installed we started with installing following packages:

  • php-mssql
  • php-pear
  • freetds

Now we need pear mbd2 driver for mssql. You can install it using following steps:

First install mdb2 driver:

$ pear install mdb2

Now install mdb2 fro mssql:

$ pear install mdb2_driver_mssql

Zend framework uses PHP Data Objects (PDO) for connecting to databases. Though there is a way to connect to databases without PDO. On Linux we will use pdo_dblib driver for connecting to MS Sql Server. You can download pdo_dblib package from (We have used version 1.0).

After downloading now we need to compile the package:

Untar the package:

 $ tar zxvf pdo_dblib.tgz

Now we use pecl command which will build the package and generate the configure script:

$ pecl build package.xml

Change to directory and run configure and make:

$ ./configure
$ make

Copy pdo_dblib to php’s modules directory :

$ cp modules/ /usr/lib/php/modules
$ vi /etc/php.d/pdo_dblib.ini

Write the following line in the file:

Next step is to configure freetds to connect MS Sql Server:

$ vi /etc/freetds.conf

And write these lines in the file:

host = <IP Address>
port = <Port Number>
tds version = 8.0

Finally set the pdo_type you specified in you project to dblib. We used a separate config.ini file, you can also do that in bootstrap.php:

pdoType = dblib

The project is deployed finally 🙂 I hope I havent missed a step. All’s well that end’s well 🙂


10 thoughts on “Connecting MSSQL Server with Zend Framework on Linux

  1. We had problems with the initial setup. We generally work on PHP and MySql projects. This was our first PHP-MsSql project.

    After the complete setup the first thing we discovered was theres no support for utf-8 in MsSql Server.

    PHP’s “mb_convert_encoding” helped us to deal with the problem.

    Currently the project is deployed and successfully 🙂

  2. Hello,

    I’ve been able to install all the packages, but i get an error when trying to make a query:
    Message: SQLSTATE[01002] Adaptive Server connection failed (severity 9)

    What params should i use for connecting using the zend db adapter? also, what adapter are you using? I’m trying with PDO_MSSQL

    Thank you,


  3. Hi
    I am trying to connecting to mssql server from core php with pdo but unable to connect it and it is showing following message:
    SQLSTATE[01002] Adaptive Server connection failed (severity 9)
    I am also trying to connect with mssql but it is not connection and showing following error message:

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xx.xx.xx.xx

    Please help me. It is urgently

    Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s