If you
where to ask 100 php programmers what the following mysql should produce
EVEN if they feel its a poor and improper method they would still assume
it would return number of rows returned.
$result2 = $db2->query('SELECT * FROM songs');
echo $result2->rowCount()."\n";
We can easily fix this misconception by providing a good example on
the rowCount() manual page.
And if you ask 100 non-MySQL programmers they would say 'HOW long does it take!' - Now that MySQL is starting to handle proper transactions, the 'cost' of calculating a count on a transaction based database needs to be considered. The only way is to 'visit' ALL records and check those that are still visible in YOUR transaction, so 'SELECT COUNT(*) FROM X' is not something that is used lightly and hiding it in rowCount just makes it worse ;)
When you start doing 'proper' client/server database management, a lot of the 'nice' features that MySQL has becomes major burdens on performance, and you then have to work out how to get round them :)
This is why MySQL is still considered a bit mickey mouse, and simply bolting on missing facilities is not an easy option.
If you just select 10 records from large dataset, then rowCount will give you 10 (or less) and you need a separate result to know the total number of records from which to select the 10, or not if you manage totals in a different way.
--
Lester Caine
-----------------------------
L.S.Caine Electronic Services