简体   繁体   中英

PHP PDO sqlsrv Undefined class constant SQLSRV_ENCODING_UTF8

I have a Codeigniter 3 app that connects to an SQL Server 2008 database. We setup a new vm with Windows server 2012 r2 64bit, SQL Server Express 2012 and xampp with 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:

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. I run PHP/CodeIgniter on several Windows servers, and have run into problems with the wrong drivers when getting things initially setup.

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. Then, in your php.ini file, you will need to make sure that both of these extensions are uncommented:

extension=php_sqlsrv_56_nts.dll
extension=php_pdo_sqlsrv_56_nts.dll

Once those two are uncommented, make sure the other references to the SQL Server drivers are commented out. If that doesn't help, here is another article to check: Xampp MS SQL server PHP 5.6 .

After adjusting the php.ini file, remember to restart the site via IIS.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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