更新时间:2023-11-19 15:58:40
在linux(至少基于Debian的发行版)下,php需要包 php5-sybase
为Sybase和MSSql提供支持。
如果您使用基于debian的发行版,您将需要执行
$ sudo apt-get install php5-sybase
/ pre>
$ sudo service apache2 restart和
php -rphpinfo(); | grepPDO驱动程序
应该给你
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.