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

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