問題描述
在非 Windows 操作系統上將 ZF2 與 MS SQL Server 結合使用的規范方法是什么(如果存在)?
What, if it exists, is the canonical way to use ZF2 with MS SQL Server on a non-Windows OS?
根據我從 文檔中了解到的內容,官方只支持Sqlsrv驅動,僅適用于Windows平臺.
From what I can tell from the documentation, only the Sqlsrv driver is officially supported, which only works on the Windows platform.
在 ZF1 中,我們使用了 Pdo_Mssql
適配器并將 pdoType
指定為 dblib
.我找不到在 ZF2 中做類似事情的任何參考.
In ZF1, we used the Pdo_Mssql
adapter and specified the pdoType
as dblib
. I can't find any references to doing anything similar in ZF2.
顯然 前一段時間有一個 Pdo\Mssql 驅動程序,它在一個主要的 重構,但我沒有看到當前記錄的使用 Pdo_Dblib 的方法.
Apparently there was a Pdo\Mssql driver some time ago which was removed during a major refactoring, but I don't see a currently documented way of using Pdo_Dblib.
根據上面的適配器文檔,您可以將適配器配置中的驅動程序設置為 Pdo=OtherPdoDriver
,但是沒有關于這種用法的文檔示例.這是否意味著您可以使用 Pdo=Pdo_Dblib
或 Pdo=dblib
并且它會自動運行?
According to the adapter documentation above, you can set the driver in the adapter config to Pdo=OtherPdoDriver
, but there's no documented examples of this usage. Does that mean you can use Pdo=Pdo_Dblib
or Pdo=dblib
and it will work automagically?
我發現傳遞了對 PDO ODBC 驅動程序的引用,這將是一個可用的替代方法,但找不到任何文檔或代碼引用.
I've found passing references to a PDO ODBC driver, which would be a usable alternative, but can't find any documentation or code references.
推薦答案
安裝 php5-sybase.確保安裝了 freetds
.您應該在 /etc/freetds
下有一個名為 freetds.conf
的 conf 文件.
Install the php5-sybase. Make sure that freetds
is installed. You should have a conf file under /etc/freetds
called freetds.conf
.
在你的 freetds.conf
文件中,你應該像這樣設置你的 mssql 連接:
In your freetds.conf
file you should setup your mssql connection like this:
[MyMsSqlServer]
host = symachine.domain.com
port = 5000
tds version = 5.0
然后,(此處以 ZF2 專輯教程為例)您可以像這樣設置適配器:
Then, (using the ZF2 Albums Tutorial as an example here) you set up the adapter like this:
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'dblib:host=MyMsSqlServer;dbname=zf2tutorial',
'charset' => 'UTF-8',
'username' => 'username',
'password' => 'password',
'pdotype' => 'dblib',
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
看看這是否能幫助您找到任何地方并告訴我.我花了一段時間讓它工作,我更樂意幫助其他有問題的人!!!
See if this gets you anywhere and let me know. I had a bitch of a time getting this to work, and I am more then happy to help anyone else that is having issues with this!!!
這篇關于如何在 *nix 上將 Zend Framework 2 與 MS SQL Server 一起使用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!