In today’s post, developer Tony White talks about how to connect to a MSSQL Database in Symfony.
So, let's say you have a Symfony application that will be hosted on a Linux Server; however, this application also needs to pull data from a Microsoft SQL Server Database filled with client data. What we’ll need is a bundle that can handle doing MSSQL ORM duties of which there are a few; however we’ll first need to configure FreeTDS on our system.
The first thing we’ll need to do is to install FreeTDS and the DBLIB PDO Driver:
sudo apt-get install freetds-bin sudo apt-get install php5-sybase
The commands above are for installation on Debian-based Linux Distros (Ubuntu in my case) but you can also install these packages on Red Hat-based Linux Distros as well (I’ve deployed a similarly configured application onto a CentOS Server).
Once these are installed we need to configure FreeTDS. To do this cd into the /etc/freetds directory and modify the freetds.conf file to look like below (with your Microsoft SQL Server Information added):
Once the freetds.conf file is configured, restart apache and you can attempt to connect to the MSSQL Server via terminal:
tsql -S [hostName] -U [userName]
This should allow you to connect to your MSSQL Database. If not, you can diagnose any error messages received here: http://www.freetds.org/userguide/confirminstall.htm
The Last step is to choose which bundle you would to use for your application. The bundle I used is the isoft/mssql-bundle. This fork was recently abandoned, but if you want to use this bundle follow the instructions for installation/configuration from here: https://packagist.org/packages/isoft/mssql-bundle
Hope this #CaxyTip is helpful! Stay tuned for more tips like these on our blog.