dpoh61610 2015-11-09 10:43 采纳率: 100%
浏览 39
已采纳

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?

  • 写回答

1条回答 默认 最新

  • dongshan3759 2015-11-13 12:58
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?