Forum Discussion
alescan
Aug 20, 2021Brass Contributor
PHP PDOStatement::rowCount problem
Hello everyone,
I have a problem with the rowCount() in this code:
$sqlLoc= "DECLARE @Data2 AS DATE;
SET @Data2 = CONVERT(DATE,CONVERT(date, '$dataIncasso'), 102);
DECLARE @Data1 AS DATE;
SET @Data1 = DATEADD(DAY, $interval, @Data2)
SELECT noteincassi.CodLocale,Insegna,Citta
FROM [Edera].[dbo].[NoteIncassi],edera.dbo.AnagraficaLocali
where DataIncasso=@Data2 AND tipoincasso='6' and AnagraficaLocali.CodLocale=NoteIncassi.CodLocale AND sospeso=0
GROUP BY noteincassi.CodLocale,insegna,Citta
ORDER BY Insegna";
$queryLoc=$conn->prepare($sqlLoc,array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
//$queryLoc->execute();
if($queryLoc->execute()){
echo $numero=$queryLoc->rowCount();
}
$id=0;
while($resultLoc=$queryLoc->fetch()){
It will print -1 but the fecth is working and row are returned,so the rest of the code is working fine, it's only the rowcount and I don't understand why.
Thank you
- mcdasaBrass ContributorI don't see why since it is php,
at least you can fake it by adding [count() over ] to select statement and use it for purpose as it be. - dga26Copper Contributor
UP
Same for us today,
Very strange behavior when iterating over multiple statement sometimes rowcount is correct, sometimes not and tracing query in standard ssms profiler, we see a line result > abort when rowcount is down
We have tried to use select @@ROWCOUNT for issue instead of rowcount (which returns -1) in vain...
We use doctrine dbal proxy for pdo_sqlsrv (5.12) driver and sqlserver 2022 for information