Refactor database queries to use parameter binding