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