Mysql statement problem

Your db is already a global var. So just create it in the main func block and not in each call.