diff --git a/config/config.sample.php b/config/config.sample.php
index 4b1ab2fce5fa24f0e5021d83d949f1c882cef11a..6da00fc12a511007d2723a2eae1a3b8b24fe14ef 100755
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -26,7 +26,7 @@ $CONFIG = array(
 /* Password to access the ownCloud database */
 "dbpassword" => "",
 
-/* Host running the ownCloud database */
+/* Host running the ownCloud database. To specify a port use "HOSTNAME:####"; to specify a unix sockets use "localhost:/path/to/socket". */
 "dbhost" => "",
 
 /* Prefix for the ownCloud tables in the database */
diff --git a/lib/private/db.php b/lib/private/db.php
index 82affe293edab44bf6d1fe4bba1c3c2f9d18da9c..8fd2ef1c6f7673415599e7541113dd1495a27edc 100644
--- a/lib/private/db.php
+++ b/lib/private/db.php
@@ -57,40 +57,34 @@ class OC_DB {
 			return true;
 		}
 
-		// The global data we need
-		$name = OC_Config::getValue( "dbname", "owncloud" );
-		$host = OC_Config::getValue( "dbhost", "" );
-		$user = OC_Config::getValue( "dbuser", "" );
-		$pass = OC_Config::getValue( "dbpassword", "" );
-		$type = OC_Config::getValue( "dbtype", "sqlite" );
-		if(strpos($host, ':')) {
-			list($host, $port)=explode(':', $host, 2);
-		} else {
-			$port=false;
-		}
-
+		$type = OC_Config::getValue('dbtype', 'sqlite');
 		$factory = new \OC\DB\ConnectionFactory();
 		if (!$factory->isValidType($type)) {
 			return false;
 		}
 
+		$connectionParams = array(
+			'user' => OC_Config::getValue('dbuser', ''),
+			'password' => OC_Config::getValue('dbpassword', ''),
+		);
+		$name = OC_Config::getValue('dbname', 'owncloud');
+
 		if ($factory->normalizeType($type) === 'sqlite3') {
 			$datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data');
-			$connectionParams = array(
-				'user' => $user,
-				'password' => $pass,
-				'path' => $datadir.'/'.$name.'.db',
-			);
+			$connectionParams['path'] = $datadir.'/'.$name.'.db';
 		} else {
-			$connectionParams = array(
-				'user' => $user,
-				'password' => $pass,
-				'host' => $host,
-				'dbname' => $name,
-			);
-			if (!empty($port)) {
-				$connectionParams['port'] = $port;
+			$host = OC_Config::getValue('dbhost', '');
+			if (strpos($host, ':')) {
+				// Host variable may carry a port or socket.
+				list($host, $portOrSocket) = explode(':', $host, 2);
+				if (ctype_digit($portOrSocket)) {
+					$connectionParams['host'] = $host;
+					$connectionParams['port'] = $portOrSocket;
+				} else {
+					$connectionParams['unix_socket'] = $portOrSocket;
+				}
 			}
+			$connectionParams['dbname'] = $name;
 		}
 
 		$connectionParams['tablePrefix'] = OC_Config::getValue('dbtableprefix', 'oc_');