AS others already showed, it is possible to do so, but in most of the scenario's I can think of, this is not a good idea.
- Unless you are guaranteed that the contents of the table will not change during the lifetime of your script, you are not going to pick up any changes to it and therefore may be working with stale data.
- If the table is very big, you will download a lot of data to a variable structure in your script, of which you perhaps only use a very small part. This is wasteful of memory and will scale very badly.
- Databases are made to be rather efficient to hand you back the answer to your queries. Over the aggregated lifetime of your script is likely that the database will do a better job than you can.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James