PHP PDOStatement::rowCount problem

Brass Contributor

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

 

1 Reply
I 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.