Ask your Symfony questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Can't get Doctrine to connect to MSSQL Server 2008 on Windows Symfony



I'm trying to follow the Practical symfony 'jobeet' tutorial at except with MS SQL Server 2008 R2 and IIS on Windows Server 2008 R2 instead of on MySQL and Apache. I'm getting a problem with Doctrine connecting to my MSSQL Server which is on the same machine as symfony, IIS and PHP. When I attempt to run the doctrine command I get

c:\jobeet>php symfony doctrine:insert-sql
>> doctrine creating tables

Couldn't locate driver named mssql

My databases.yml contains the following:
class: sfDoctrineDatabase
dsn: 'mssql:host=localhost;dbname=jobeet'
username: sa
password: my_sa_password

I have been following the instructions at the More With Symfony book at ... nd-Symfony in order to get symfony installed and running on Windows with IIS. To that end, I installed PHP using the Web Platform Installer from as was detailed in More with Symfony. I also installed the Microsoft SQL Driver 2.0 for PHP v5.3 in IIS, thinking that was needed.

So when I check my PHP installation at C:\Program Files (x86)\PHP\v5.3 that WPI installed, in the ext folder there's a php_sqlsrv.dll, php_pdo_sqlsrv.dll, php_pdo_odbc.dll but no php_mssql.dll or php_pdo_mssql.dll. Is there supposed to be a php_mssql.dll? What package do I need to install to get that support? How do I install it?

I'm assuming php_sqlsrv.dll and php_pdo_sqlsrv.dll are the Microsoft SQL Driver 2.0 for PHP v5.3 in IIS, but when I try to change the dsn in databases.yml to either 'sqlsrv:host=localhost;dbname=jobeet' or 'pdo_sqlsrv:host=localhost;dbname=jobeet', I get the error 'Unknown driver sqlsrv' and 'Unknown driver pdo_sqlsrv' I also tried adding an odbc connection and using 'odbc:host=localhost;dbname=jobeet' and still got a similar error. What is the correct syntax for the the dsn for the different databases? Why doesn't Doctrine support the Microsoft SQL Driver for PHP? Which package do I need to install to get dll needed for the Doctrine support for MSSQL?

The only mention of the MSSQL drivers in the More with Symfony book is the following. The tutorial doesn't actually use the drivers, it uses the SQLite driver.

Planned Extension for this Tutorial
A supplemental section of this chapter is in the works and will be released on the symfony
project web site shortly after the publication of this book. It covers the connection to MS
SQL Server via PDO, something Microsoft is planning improvements for soon.
Currently, the best performance in code execution is obtained by the Microsoft native SQL
Server driver for PHP 5, an open-source driver available on Windows and currently
available in version 1.1. This is implemented as a new PHP extension DLL:
It is possible to use either Microsoft SQL Server 2005 or 2008 for the database. The planned
tutorial extension will cover the usage of the edition that is available for free: SQL Server

It doesn't look like that Planned Extension was ever updated to be part of the tutorial.

Answers (1)


Loban Rahman answers:

I found this blog post with some info regarding getting Symfony 1.4 and Doctrine 1.2 working with MSSQL Server 2008 and using PHP 5.2

Loban Rahman comments:

The site suggest sticking to PHP 5.2 to use the php_mssql and php_pdo_mssql drivers, and to use the cp1252 charset instead of UTF-8.