How to count rows from a table with PDO

Asked

Viewed 1,683 times

1

I’m trying to get the number of lines a Select to show or not some messages to the user, but all possible attempts did not return me the correct result. What I’m using is a William Francisco Leite class that suits me perfectly, but I can’t get the total lines as desired.

What I got is this:

// CONEXÃO PDO   
$pdo = Conexao::getInstance();
$crud = Crud::getInstance($pdo, 'cadDolar');

The code of the search:

$sqlMaxDolar = "SELECT DATE_FORMAT(MAX(Data),'%Y-%m-%d') as DataDolar FROM cadDolar";
$arrayParam = array();
$ResMaxDolar = $crud->getSQLGeneric($sqlMaxDolar, $arrayParam, TRUE);
$QtdeMaxDolar = count($ResMaxDolar);

At your suggestion:

print_r($ResMaxDolar);
Resultado: Array ( )

The result of this query should be 1 but is returning 0.

I’ve tried with the rowCount, but the manual itself says that it is not reliable to use .

  • Gave a print_r(Resmaxdolar); to check if it is locating any database record?

1 answer

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.