Move database connection to a separate function.

Move connection information to a constant.