If you find yourself trying to connect to a MSSQL database in your Symfony 2 project that is running on Linux you will soon discover that it does not work. Even if you have figured out how to connect to MSSQL with PHP itself as outlined here.
Doctrine 2 currently supports drivers called sqlsrv, which is Windows only, and pdo_sqlsrv. The later creates a dsn in its driver class (Doctrine\DBAL\Driver\PDOSqlsrv\Driver) that looks like this:
When it should actually be this:
So what we need is a custom driver class that creates the correct connection instance. Fortunately this already exists and can be installed via composer:
The docs for this bundle state that you need to install FreeTDS, configure a connection and use that connection name as the value for the
host key in your
I have not found that to be necessary on Linux. And on OSX if you follow this I did not see the need for it either.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Notice that the
driver parameter is commented out and a new parameter called
driver_class is added, which tells doctrine to use the custom driver class that we installed.