move sql from templates, and replace mysql with queryDB()