Database Improvements

Ongoing work to replace all of TheyWorkForYou's raw queries with nice shiny PDO prepared statements.
What do you mean, sorry? I didn't change the SQL in that refactoring of templates, so I meant that this change still needs to be made, but the code is no longer where this change had it.