Connecting Symfony to SQL Server

This is the second of my posts documenting how I configured the PHP Symfony framework for Windows. For work, I needed to connect my Symfony installation to SQL Server. There are two steps to do so: install the driver and update the configuration settings.

First, download the Sql Server driver:
https://docs.microsoft.com/en-us/sql/connect/php/download-microsoft-php-driver-for-sql-server

Then copy the appropriate dll to your PHP ext folder.

This page will tell you which dll to choose: http://php.net/manual/en/ref.pdo-sqlsrv.php

Next, add the dll file name to your php.ini config file, like this:

extension=php_pdo_sqlsrv_53_nts.dll

Then restart the web server.

Finally, you need to update the Symfony config. In your app/config folder change the driver under the doctrine section to:

pdo_sqlsrv

For security reasons, your other configuration settings will likely already be set to variables. Those variables can be found in parameters.yml.

In the parameters config, update any connection settings as necessary to match the setup of your database.

Advertisements