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
.
fetchAll
is something I won't want because I may sometimes be dealing with large datasets, so not good for my use.
Do you have any suggestions?
Not the most elegant way to do it, plus it involves an extra query.
PDO has
PDOStatement::rowCount()
, which apparently does not work in MySql. What a pain.From the PDO Doc:
EDIT: The above code example uses a prepared statement, which is in many cases is probably unnecessary for the purpose of counting rows, so: