Below is the current code I use to get the total number of photos in a DB, An estimated number would even be acceptable as the number of results is just used to determine which folder number I would like to upload into for folder balance of files.
I have a feeling there is a better way then I am using below?
$sql = 'SELECT auto_id FROM friend_user_photo';
$query = executeQuery($sql);
$rowcount = mysql_num_rows($query);
$rowcount returns number of record in the friend_user_photo table
UPDATE:
Isn’t there a way to read information about a database. that might be quicker then using above method or COUNT?
You can also use COUNT.
This will return a single row containing the number of results. This is also a regular aggregate function so you can do joins, sub queries, conditions (WHERE), grouping and all that good stuff.
You can also treat this as just another field, so you can alias it and then use it in your joins and sub queries. You can also select additional data, for example:
This will return a distinct list of names, but will also contain the number of records that exist for each of those names.
Edit for alternative to count()
If you don’t want to use COUNT(*) you can also use ‘show table status’. For example:
This will return a row with various meta-data including Rows, but also including Key Length (in bytes) and Data Length (in bytes) as well as a lot of other data. This is also usually quite fast since it’s just pulling meta-data as apposed to running an aggregate function like COUNT(*) (so long as the table isn’t locked by another query that’s currently running).