Refactor OC_DB::connect() to properly support sockets.

Based on #8888 by @josh4trunks which is being replaced by this.
Fixes #3157 #3158 according to https://github.com/owncloud/core/pull/8888#issuecomment-45183324