fix db writing global var issue