将Symfony2连接到MS SQL Server
我使用MySQL与Symfony2合作,现在我被要求使用MS SQL Server处理它。我该怎么办?我应该添加到parameters.ini文件?感谢提前。
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.
可能是我要写的重申在引用的@walid的帖子中,但是通过快速浏览它,我没有看到它...
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...
首先,当使用MSSQL时,您需要 pdo_sqlsrv驱动程序。只需将您需要的版本(PHP 5.3 / 5.4 nts / ts)复制到PHP的 ext /
文件夹中,将扩展名添加到您的php.ini中,然后重新启动apache。存档包含 pdo_sqlsrv * .dll
和 sqlsrv * .dll
,因此请确保使用 pdo_ * 强>!如果扩展程序成功加载,您可以通过 phpinfo()
进行检查。
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.
您的parameters.ini将保持几乎相同,除了database_driver,显然应该设置为 pdo_sqlsrv
。没有必要在parameters.ini中指定一个端口,但是如果你想要的话,MSSQL的默认端口是1433。
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.
只是一个例子,你的参数。 ini应该看起来像这样:
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
作为旁注,我只使用yaml-config,所以这可能不是100%正确!
As a sidenote, I only use the yaml-config, so this might not be 100% correct!