fix bug with undefined database var (2)