For the number of SQL rows, is it more efficient to use PDO rowCount or count (*) AS?


On my script, I have about 15 SQL queries just for counting the number of rows and displaying them to the user.

What is the most efficient way?

Should I use:

$stmt=$cxn->prepare("SELECT id FROM items WHERE seller=?");
echo $stmt->rowCount();

Or this:

$stmt=$cxn->prepare("SELECT count(*) as count FROM items WHERE seller=?");
    echo $row['count'];

Thanks in advance.

The short answer is Count(*) will be faster.

However, that assumes your not using the data, if you are going to select the data, and you want a count, then use your first method.

("SELECT id FROM items WHERE seller=?");

If you have an index on the table, then that will return almost instantly.