Add db constructor

Instead of relying on a particular function to be called, the
declaration of $db now occurs on construct.