From e29dd34d6970ca9a5b45dd5f283e29e6a2a83465 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 13 Jan 2017 16:27:05 +0100 Subject: [PATCH] Do not require database port configuration --- daos/mysql/Database.php | 12 +++++++++++- daos/pgsql/Database.php | 12 +++++++++++- defaults.ini | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/daos/mysql/Database.php b/daos/mysql/Database.php index 63ff047fb5..2a0bfbf000 100644 --- a/daos/mysql/Database.php +++ b/daos/mysql/Database.php @@ -28,9 +28,19 @@ class Database { */ public function __construct() { if(self::$initialized===false && \F3::get('db_type')=="mysql") { + $host = \F3::get('db_host'); + $port = \F3::get('db_port'); + $database = \F3::get('db_database'); + + if ($port) { + $dsn = "mysql:host=$host; port=$port; dbname=$database"; + } else { + $dsn = "mysql:host=$host; dbname=$database"; + } + \F3::get('logger')->log("Establish database connection", \DEBUG); \F3::set('db', new \DB\SQL( - 'mysql:host=' . \F3::get('db_host') . ';port=' . \F3::get('db_port') . ';dbname='.\F3::get('db_database'), + $dsn, \F3::get('db_username'), \F3::get('db_password'), array(\PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES utf8mb4;') diff --git a/daos/pgsql/Database.php b/daos/pgsql/Database.php index 488de373fe..0559c4fc7a 100644 --- a/daos/pgsql/Database.php +++ b/daos/pgsql/Database.php @@ -35,9 +35,19 @@ class Database { */ public function __construct() { if (self::$initialized === false && \F3::get('db_type')=="pgsql") { + $host = \F3::get('db_host'); + $port = \F3::get('db_port'); + $database = \F3::get('db_database'); + + if ($port) { + $dsn = "pgsql:host=$host; port=$port; dbname=$database"; + } else { + $dsn = "pgsql:host=$host; dbname=$database"; + } + \F3::get('logger')->log("Establish database connection", \DEBUG); \F3::set('db', new \DB\SQL( - 'pgsql:host=' . \F3::get('db_host') . ';port=' . \F3::get('db_port') . ';dbname='.\F3::get('db_database'), + $dsn, \F3::get('db_username'), \F3::get('db_password') )); diff --git a/defaults.ini b/defaults.ini index 3c36fc56df..038a664b97 100644 --- a/defaults.ini +++ b/defaults.ini @@ -7,7 +7,7 @@ db_host=localhost db_database=selfoss db_username=root db_password= -db_port=3306 +db_port= db_prefix= logger_level=ERROR items_perpage=50