add support for custom ports for mysql/pgsql by adding :portnumber to the database host

This commit is contained in:
Robin Appelman 2012-05-17 01:06:22 +02:00
parent 5fe7200a7f
commit aac9629e88
1 changed files with 15 additions and 2 deletions

View File

@ -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{