'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?
Solution 1:[1]
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.
Solution 2:[2]
For people searching for a solution for this error, I fixed it by specifying a default TCP port in SQL Server Configuration Manager.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Muhamad Bhaa Asfour |