How to count rows of a table with PDO

1

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

What I have is this:

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

The search code:

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

As suggested:

print_r($ResMaxDolar);
Resultado: Array ( )

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

I have tried with rowCount , but the manual itself says it is not trustworthy to use.

    
asked by anonymous 22.06.2017 / 15:36

1 answer

2

Turning the result into array and giving a count is an alternative

$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

$result = $sth->fetchAll();
count($result);

link

    
22.06.2017 / 15:52