In Mysql $stmt->rowCount(); doesnt work. Try this
$nRows = $pdo->query('select count(*) from yourTable')->fetchColumn();
echo 'Number of rows is = '. $nRows;
Here is an excerpt from a comment and answer regarding the same. Check it out its very resourceful.
mysql_num_rows() worked is because it was internally fetching all the rows to give you that information, even if it didn't seem like it to you. Refer to this anwere
So in PDO, your options are:
- Use MySQL's FOUND_ROWS() function.
- Use PDO's fetch_all() function to fetch all the rows into an array,
then use count() on it.
- Do an extra query to SELECT COUNT(*),
https://stackoverflow.com/a/883523/2536812