I have a prepared query with 3 result sets. I used fetch()
for the first two since they only have one row each and they are appearing correctly in the View. For the 3rd result set, it consists of several transaction rows and I used fetchAll()
, but it is empty, nothing appears in the view.
I tried modifying the proc to only return this transaction list, so in my code, I only called fetchAll()
, but it is still empty. I've also tried running the EXEC
statement in MS SQL Management Studio, and I can confirm that the 3rd query was supposed to return rows. I also didn't use fetchColumn()
anywhere in the code. rowCount()
returns 0.
I am now stuck. Please help.
Code snippet below:
try {
$conn = new PDO($dsn,$un,$pw);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
print("Error connecting to SQL Server.");
die(print_r($e));
}
$stmt = $conn->prepare("EXEC SomeStoredProc ?,?,?");
$stmt->execute([$id,$fromDate,$toDate]);
$firstResult_ = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->nextRowset();
$secondResult = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->nextRowset();
$transactions = $stmt->fetchall(PDO::FETCH_ASSOC);
$sample = $stmt->rowCount(); //returns 0