Database layer

Implements https://github.com/elkarte/Elkarte/issues/398