Replace remaining uses of deprecated db_num_rows() function

The db_num_rows() function is deprecated as some databases do not know how
many rows are being returned until all rows have been requested from the
server. We therefore have to perform the row count ourselves - when
necessary.

In many cases it may make more sense to perform a SELECT(*) query to
retrieve counts. This is less costly than returning data that we're not
going to use. This is something to consider in the future as the core is
upgraded to use more modern/robust database queries.
Again, avoid loading all notes in an array to avoid getting the count.