连接主义2到MSSQL为SYMFONY 2在Linux上 [英] Connecting Doctrine 2 to MSSQL For SYMFONY 2 On Linux
问题描述
我正在尝试使用Doctrine 2(Symfony 2)从linux机器连接到MSSQLServer。
我已经安装了pdo_dblib(PDO Driver for FreeTDS / Sybase DB-lib),并且能够通过命令行上的tsql和php cli连接到db服务器。因此我知道这是正常工作。
在我的Symfony / app / config / parameters.ini文件中,我指定了database_driver =pdo_sqlsrv作为数据库驱动程序但是当尝试运行一个create database命令(使用命令 php app / console doctrine:database:create ...)时,这将由
db_lib
/ code>)我收到错误:
无法创建连接名称的数据库找不到驱动程序
然后,我将驱动程序更改为 database_driver =pdo_dblib
,我现在得到错误:
[Doctrine\DBAL\DBALException]
给定的'driver'pdo_dblib是未知的,Doctrine目前支持
只有以下驱动程序:pdo_mysql,pdo_sqlite,pdo_pgsql,pdo_oci,
oci8,ibm_db2,pdo_ibm,pdo_sqlsrv
所以似乎连接到MSSQL我唯一的选项是 pdo_ sqlsrv
,所以我去安装了。但是,我刚刚在这里发现,那个
PDO_SQLSRV扩展仅与在Windows上运行的PHP兼容。
在linux(至少基于Debian的发行版)下,php需要包 php5-sybase
为Sybase和MSSql提供支持。
如果您使用基于debian的发行版,您将需要执行
$ sudo apt-get install php5-sybase
/ pre>
$ sudo service apache2 restart
和
php -rphpinfo(); | grepPDO驱动程序
应该给你
< blockquote>
PDO驱动程序:dblib,mysql,sqlite,...
dblib
实际上是我们需要的
现在可以使用这个驱动与Doctrine,这篇文章:
Doctrine 2 - 如何添加自定义DBAL驱动程序?帮助我找到
OP建议使用此捆绑在git 上,使事情一起工作。
I am trying to use Doctrine 2 (for Symfony 2) to connect to MSSQLServer from a linux machine.
I have installed pdo_dblib (PDO Driver for FreeTDS/Sybase DB-lib) and am able to connect to the db server via tsql on the command line and from the php cli also. Thus I know this is working.
In my Symfony/app/config/parameters.ini file I had specified database_driver="pdo_sqlsrv" as the database driver (as I read that this would be handled by
db_lib
) but when trying to run a create database command (using the commandphp app/console doctrine:database:create
) I am getting the error:Could not create database for connection named could not find driver
I then changed the driver to
database_driver="pdo_dblib"
and I am now getting the error:[Doctrine\DBAL\DBALException]
The given 'driver' pdo_dblib is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_ibm, pdo_sqlsrvSo it seems that to connect to MSSQL my only option is
pdo_sqlsrv
, so I went to install this. However, I have just discovered here, thatThe PDO_SQLSRV extension is only compatible with PHP running on Windows.
Thus the driver supported by doctrine and those available to use on linux seem to be mutually exlusive. From searching I haven't found any instances of this issue being solved thus far (One guy marked the issue as solved, but when I read the thread he had simply moved his dev env to a windows box... not exactly what I had in mind!).
解决方案Under linux (at least Debian based distros), php needs the package
php5-sybase
that brings support for Sybase and MSSql.If you are using a debian based distribution you will want to do
$ sudo apt-get install php5-sybase $ sudo service apache2 restart
And
php -r "phpinfo();" | grep "PDO drivers"
should give you
PDO drivers: dblib, mysql, sqlite, ...
dblib
is actually the one we needNow to be able to use this driver with Doctrine, this post: Doctrine 2 - How to add custom DBAL driver? helped me to find the answer.
The OP suggests to use this bundle on git that makes things work together.
这篇关于连接主义2到MSSQL为SYMFONY 2在Linux上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!