Refactor DAO
- Pulled out similar code from all functions to merge into one that can be called separately
- Removed a couple of functions which could be merged into more utilised functions
- MySQL function calls should now be escaped to prevent injection
- Tried to reduce number of queries in some functions to avoid hammering the database