Skip to content

Commit

Permalink
Merge pull request #843 from jtojnar/db-optional-port
Browse files Browse the repository at this point in the history
Do not require database port configuration
  • Loading branch information
SSilence authored Feb 4, 2017
2 parents 5dc63bc + e29dd34 commit c926c67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion daos/mysql/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;')
Expand Down
12 changes: 11 additions & 1 deletion daos/pgsql/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
));
Expand Down
2 changes: 1 addition & 1 deletion defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c926c67

Please sign in to comment.