SELECT COUNT(*) FROM (?)时出问题，无法set进这个表名，说sql语法错：（不知道怎么回事：（
I don't know there is a better way than get count(*) in general.
Maybe you should look at how to cluster the table for better performance, but it varies on database, for mysql, I don't know the option.
I have use getCount(*) in mysql on a table with over 300,000 records, most of time it returns within a couple of seconds. that table reside on INNODB, if you using ISAM, it should even faster, as base on mysql doc, when count(*) with where, it use MyISAM table instead of full table scan.
You can do prepared statement that way, only the param for where can be bind, plus I don't think you have any gain here as with where clause or join, execution plan is very easy to prepared.