douwang6635 2015-12-08 14:44
浏览 67
已采纳

PHP + SQL Server,SQL可以工作,但RESET标志在服务器响应中设置

I'm experiencing odd behavior when working with PHP and the PDO extension for SQL Server, on a Windows machine with an Apache web server. I added the necessary .dlls to /php/ext to enable the extensions, and phpinfo shows that sqlsrv has been installed/loaded. I also installed the SQL Server native client. However when accessing a page that simply connects to a SQL Server database and executes a simple INSERT query, the web server responds with the error ERR_CONNECTION_RESET. I checked the packet and the Reset flag is being set; I also checked the database and the INSERT query actually does successfully execute, with new rows being added, but the web server is for some reason setting the Reset flag. Does anyone know what's going on here?

Edit: It seems as though INSERT or UPDATE statements work, but SELECT statements cause the ERR_CONNECTION_RESET flag.

There is no antivirus running and no proxies, and the page loads without the ERR_CONNECTION_RESET if the code that makes the INSERT query is commented out.

For what it's worth, here's the code:

// This does not cause the ERR_CONNECTION_RESET error
$pdo = new PDO('sqlsrv:Server=' . $host . ';Database=' . $database, $user, $pass);
$stmt = $pdo->prepare("INSERT INTO Table1 (Col1, Col2) VALUES ('test', 4)");
$stmt->execute();

// This causes the ERR_CONNECTION_RESET error
$pdo = new PDO('sqlsrv:Server=' . $host . ';Database=' . $database, $user, $pass);
$stmt = $pdo->prepare("SELECT Col1, Col2 FROM Table1");
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
  • 写回答

2条回答 默认 最新

  • doucheng3407 2015-12-08 16:12
    关注

    I discovered the problem. After checking the Windows Event Log, I noticed some entries associated with the Apache executable. Looking in these entries, the php .dll was flagged as a fault module. I replaced that with the .dll that worked on a different computer, and I am no longer experiencing this error.

    A faulty PHP .dll caused the Apache server to crash, resulting in the server error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?