Connect Symfony2 to MS SQL Server

2020-06-28 06:22发布

问题:

I worked with Symfony2 using MySQL and now i'm asked to work with it using MS SQL Server. How can i procede? what should i add to the parameters.ini file ? Thanks in advance.

回答1:

It might be that what I'm about to write reiterates something in the post @walid referenced, but by just quickly glancing at it I didn't see it...

First of all, when using MSSQL you need the pdo_sqlsrv driver. Just copy the version you need (PHP 5.3/5.4 nts/ts) into your PHP's ext/ folder, add the extension to your php.ini and then restart apache. The archive contains both pdo_sqlsrv*.dll and sqlsrv*.dll, so make sure you use pdo_*! You can check via phpinfo() if the extension was loaded successfully.

Your parameters.ini will stay pretty much the same, except for the database_driver, which obviously should be set to pdo_sqlsrv. It should not be necessary to specify a port in the parameters.ini but in case you want to, MSSQL's default port is 1433.

Just as an example, your parameters.ini should look something like this:

database_driver =   pdo_sqlsrv
database_host =     127.0.0.1
database_port =     1433
database_name =     Northwind
database_user =     DatabaseUser
database_password = DatabaseUserPassword

As a sidenote, I only use the yaml-config, so this might not be 100% correct!



回答2:

Here is how I did with Linux (Debian):
https://stackoverflow.com/a/11434909/305189

I basically installed php5-sybase and used it with this bundle