There are many conflicting statements around. What is the best way to get the row count using PDO in PHP? Before using PDO, I just simply used mysql_num_rows
.>
As I wrote previously in an answer to a similar question, the only reason 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.
So in PDO, your options are:
count()
on it.SELECT COUNT(*)
, as karim79 suggested.SQL_CALC_FOUND_ROWS
or a LIMIT
clause (in which case the number of rows that were returned by the query and the number returned by FOUND_ROWS()
may differ). However, this function is deprecated and will be removed in the future.