php 访问 mssql 2005 数据库、sqlsrv 驱动程序

php access mssql 2005 database, sqlsrv drivers

我正在尝试使用 Microsoft 提供的 sqlsrv 驱动程序访问 mssql 2005 数据库。我已经尝试了从 3.1 到 2.0 的每个驱动程序版本,安装了不同版本的 XAMPP 和安装了不同版本的 PHP。

This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86

This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client ODBC Driver to communicate with SQL Server. Neither of those ODBC Drivers are currently installed. Access the following URL to download the Microsoft SQL Server 2008 R2 Native Client ODBC driver for x86:

Php drivers are unrecognized and do not appear in phpinfo().

我的印象是扩展应该 support SQL Server 2005 及更高版本的所有版本...

我安装了 SQL Server 2012 Native Client 和 SQL Server 2008 Native Client (SP3)。 根据 this 文章,我可以测试与 SQL 服务器的 ODBC 连接。

在命令提示符处输入 odbcping returns:

'odbcping' is not recognized as an internal or external command....

我检查了 ODBC 数据源管理器,发现 SQL 服务器的 ODBC 驱动程序 11 列在驱动程序选项卡中。

关于我可能遗漏的任何帮助?

您混淆了两件事:ODBC 和 PHP MS SQL Server 2005 的驱动程序。

  • 如果安装 SQLDRV 3.X,则不会使用 ODBC。
  • 如果您使用 ODBC,那么您可能需要与 SQLDRV 不同的 PHP 驱动程序。

我也花了几个小时设置 PHP 连接到 MS SQL Server 2003、2005、2008 和 Studio Express。我使用了通过 Microsoft 提供的 SQLDRV 驱动程序安装的 pdo_sqldrv 驱动程序。安装 PHP 驱动程序很简单。一旦你在 phpinfo() 中看到 pdo_sqldrv,你就完成了 PHP 驱动程序。第二部分比较困难 - 正确设置 MSSQL 环境以允许 PHP 进行连接。我做了以下步骤:

  • 下载并安装了免费的 MSSQL Studio Express 2005(或 2008,两者都可以正常工作)
  • 已安装或升级到 dotNetFx40Setup.exe
  • 已安装 msxml6.msi(我认为只有 2005 版才需要)
  • 已安装 MSSQL 本机客户端
  • 登录工作室并为 PHP 创建了仅具有 read/write 权限的新用户
  • 启用管道和其他连接资源
  • 找到正确的连接字符串"sqlsrv:server=PCHOME\SQLEXPRESS;database=eshop"

然后它成功了,但绝对不是简单的设置。祝你好运。