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条)

报告相同问题?