msphpsql: PHP hangs on PDOStatement::fetch for large SELECT query
.+Please check the FAQ (frequently-asked questions) first. If you have other questions or something to report, please address the following:
+## PHP Driver version or file name
- pdo_sqlsrv and sqlsrv 5.8.1
+## SQL Server version
- SQL server standard (64 bit) Version: 11.0.3128.0
+## Client operating system
- Linux Debian 9 and Arch Linux
+## PHP version
- 7.4.11
+## Microsoft ODBC Driver version
- 5.8.1
+## Table schema +
+## Problem description
- PHP will hangs once it get to a certain number of records depending of the query… usually in the several thousands range.
+## Expected behavior and actual behavior
- The query complete instead of hanging at a specific record
+## Repro code or steps to reproduce
<?php
error_reporting(E_ALL);
try {
$conn = new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx;Database=Accpac', 'user', 'pass');
$sql = 'SELECT FIELD1, FIELD2, FIELDX FROM TABLE';
$stmt = $conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$stmt->execute();
$number_row = 0;
while ( $row = $stmt->fetch() ){
$number_row++;
if (($number_row % 1000) == 0) {
echo $number_row . PHP_EOL;
}
if (($number_row > 48000)) {
echo $number_row . PHP_EOL;
}
}
echo "END";
print $stmt->rowCount();
} catch ( PDOException $e ) {
print $e->getMessage();
die();
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (11 by maintainers)
I was meaning the clause ORDER BY either ASC or DESC. See below the complete schema. I will track down the exact rows once I get a chance.
@yitam @v-chojas indeed I was able to fetch the complete result set by disabling MARS !!
Thank you very much for your help.
Should I close the ticket or let it open to further investigate the issue ?