switch mysql calls to PDO and moved database calls to functions returning values