diff --git a/lib/db.php b/lib/db.php index 9f951d645e4..08bd06df95e 100644 --- a/lib/db.php +++ b/lib/db.php @@ -96,6 +96,11 @@ class OC_DB { $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; + } $opts = array(); $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); @@ -110,11 +115,19 @@ class OC_DB { $dsn='sqlite:'.$datadir.'/'.$name.'.db'; break; case 'mysql': - $dsn='mysql:dbname='.$name.';host='.$host; + if($port){ + $dsn='mysql:dbname='.$name.';host='.$host.';port='.$port; + }else{ + $dsn='mysql:dbname='.$name.';host='.$host; + } $opts[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES 'UTF8'"; break; case 'pgsql': - $dsn='pgsql:dbname='.$name.';host='.$host; + if($port){ + $dsn='pgsql:dbname='.$name.';host='.$host.';port='.$port; + }else{ + $dsn='pgsql:dbname='.$name.';host='.$host; + } break; } try{