I have the following code:
$stmt = sqlsrv_query($conn, $sql, $params);
$stmtForCounting = $stmt;
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
*table creation code*
}
So far it works, but when I add a bit to it so it looks like this:
$stmt = sqlsrv_query($conn, $sql, $params);
$stmtForCounting = $stmt;
while (sqlsrv_fetch($stmtForCounting)){
}
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
*table creation code*
}
The $stmt variable becomes empty. Using sqlsrv_fetch($stmtForCounting) shouldn't affect $stmt, right?
(The original code was longer but I stripped it down to this trying to isolate the problem.)
Edit: It is not Empty because var_dump($stmt) still says resource(9, SQL Server Statement) but the while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){*more code*} in the table creation section won't even run once.