简体   繁体   English

PHP PDO sqlsrv 未定义类常量 SQLSRV_ENCODING_UTF8

[英]PHP PDO sqlsrv Undefined class constant SQLSRV_ENCODING_UTF8

I have a Codeigniter 3 app that connects to an SQL Server 2008 database.我有一个连接到 SQL Server 2008 数据库的 Codeigniter 3 应用程序。 We setup a new vm with Windows server 2012 r2 64bit, SQL Server Express 2012 and xampp with php 5.6.我们使用 Windows server 2012 r2 64bit、SQL Server Express 2012 和 xampp 使用 php 5.6 设置了一个新的虚拟机。

We moved the app to it, installed the MSODBC and added the pdo_sqlsrv version 3.2 dll to the extensions folder and loaded it in the ini file, but when we started the app we got this error message:我们将应用程序移至其中,安装了 MSODBC 并将 pdo_sqlsrv 3.2 版 dll 添加到扩展文件夹并将其加载到 ini 文件中,但是当我们启动应用程序时,我们收到此错误消息:

Undefined class constant SQLSRV_ENCODING_UTF8 in pdo_sqlsrv_driver.php on line 144

I checked the docs and everything seems right, so we tried reinstalling everything with no luck.我检查了文档,一切似乎都正确,所以我们尝试重新安装所有内容,但没有成功。 What possibly could be the problem?可能是什么问题?

You likely have the wrong PDO driver in your PHP install.您的 PHP 安装中可能有错误的 PDO 驱动程序。 I run PHP/CodeIgniter on several Windows servers, and have run into problems with the wrong drivers when getting things initially setup.我在几个 Windows 服务器上运行 PHP/CodeIgniter,并且在最初设置时遇到了错误驱动程序的问题。

Since you are on PHP 5.6, you need to make sure the php_pdo_sqlsrv_56_ts.dll OR php_pdo_sqlsrv_56_nts.dll driver is in the PHP /ext/ directory.由于您使用的是 PHP 5.6,您需要确保php_pdo_sqlsrv_56_ts.dllphp_pdo_sqlsrv_56_nts.dll驱动程序位于 PHP /ext/目录中。 Then, in your php.ini file, you will need to make sure that both of these extensions are uncommented:然后,在您的php.ini文件中,您需要确保取消注释这两个扩展名:

extension=php_sqlsrv_56_nts.dll扩展名=php_sqlsrv_56_nts.dll
extension=php_pdo_sqlsrv_56_nts.dll扩展名=php_pdo_sqlsrv_56_nts.dll

Once those two are uncommented, make sure the other references to the SQL Server drivers are commented out.一旦这两个被取消注释,请确保对 SQL Server 驱动程序的其他引用被注释掉。 If that doesn't help, here is another article to check: Xampp MS SQL server PHP 5.6 .如果这没有帮助,请查看另一篇文章: Xampp MS SQL server PHP 5.6

After adjusting the php.ini file, remember to restart the site via IIS.调整好php.ini文件后,记得通过IIS重启站点。

对于寻找此错误解决方案的人,我通过在 SQL Server 配置管理器中指定默认 TCP 端口来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM