SQLSRV仅适用于CLI,但不适用于APACHE Web服务器
I am using sqlsrv to connect to an MS SQL database on my localhost without any problem. Recently, I have installed the 'sqlsrv' driver on a test server running Windows Server 2012 R2, that uses the same version of PHP as my localhost (php 5.5.19 - xampp)
.
Running database scripts from CLI of the test server works PERFECTLY fine.
eg: "D:\MYXAMPP\php\php.exe D:\MYXAMPP\htdocs\test\test.php
" will connect to an mssql db, select some content and print it to screen without error.
However, same scripts complain driver not found when opened from Web interface. I tried checking php error logs, and i found a startup error
"PHP Warning: PHP Startup: Unable to load dynamic library 'D:\MYXAMPP\php\ext\php_sqlsrv_55_ts.dll' - The specified module could not be found.
PHP Warning: PHP Startup: Unable to load dynamic library 'D:\MYXAMPP\php\ext\php_pdo_sqlsrv_55_ts.dll' - The specified module could not be found."
I tried restarting apache but same error keeps showing up. What could be the problem?
我使用sqlsrv连接到我的localhost上的MS SQL数据库没有任何问题。 最近,我在运行Windows Server 2012 R2的测试服务器上安装了“sqlsrv”驱动程序,该服务器使用与我的localhost 从测试服务器的CLI运行数据库脚本完全正常。
eg:“ 但是,从Web界面打开时,相同的脚本会报警驱动程序未找到 。 我尝试检查php错误日志,我发现启动错误 p>
我尝试重启apache但同样的错误不断出现。 可能是什么问题? p>
div>(php 5.5.19 - xampp) code>相同的PHP版本。 p>
D:\ MYXAMPP \ php \ php.exe D:\ MYXAMPP \ htdocs \ test \ test.php code>“将连接到mssql数据库,选择一些内容并将其打印到屏幕而不会出现错误。 p>
“PHP警告:PHP启动:无法加载动态库'D:\ MYXAMPP \ php \ ext \ php_sqlsrv_55_ts .dll' - 找不到指定的模块。
NPHP警告:PHP启动:无法加载动态库'D:\ MYXAMPP \ php \ ext \ php_pdo_sqlsrv_55_ts.dll' - 找不到指定的模块。“
code> pre>
I found a solution this problem. It turns out the server environment Visual C++ Redistributable x86 version. As pointed out in this answer, the architecture of sqlsrv extension is x86, thus requires the x86 VC++ even on a x64 machine.
I noticed this when starting apache using a batch script distributed with xampp, instead of using the xampp control panel, a pop up would occur stating "Missing MSVCP110.dll", which I found was linked to VC++ 2012. I downloaded it from microsoft's website, and restarted apache without any errors. From there on SQLSRV has been working fine for both APACHE and CLI interfaces.
I still don't know why in the first place the CLI php API loaded the extension, while the apache php API couldn't in the same environment. I am researching that.