in reply to Re: SELECT COUNT and DBI: rows
in thread SELECT COUNT and DBI: rows

If you want to do some function on your database, but only if there is something there to do it on, you could do the "two step" you suggested (COUNT (*) is very fast and fuly optimized in mySQL, so it does not "hurt" your database much), BUT your queries are not atomic and it could be that between your first step and the second step someone changed (deleted or added) the number of records so the result of your first test becomes invalid.

Therefore, only do the second step and wrap the fetch-function in a while-loop. If you get no results out of your SELECT, the code inside the while-loop will not get executed and no harm is done.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law