diff options
| author | 2019-10-05 15:48:03 +0200 | |
|---|---|---|
| committer | 2019-10-05 15:48:03 +0200 | |
| commit | 77afd1393e461a20d6d04c07dea0756e792636d5 (patch) | |
| tree | e0d0f90288cd505edca30332f2f35a87c262aa50 | |
| parent | 38932ee3bb3ccd41c0e2d79329e2d77fb5995256 (diff) | |
Add optional database connection URI parameters (#2552)
#fix https://github.com/FreshRSS/FreshRSS/issues/2549
| -rw-r--r-- | config.default.php | 25 | ||||
| -rw-r--r-- | lib/Minz/ModelPdo.php | 7 |
2 files changed, 19 insertions, 13 deletions
diff --git a/config.default.php b/config.default.php index a38a9372a..d885a8dea 100644 --- a/config.default.php +++ b/config.default.php @@ -123,33 +123,38 @@ return array( //CURLOPT_PROXYUSERPWD => 'user:password', ), - 'db' => array( + 'db' => [ - # Type of database: `sqlite` or `mysql`. + # Type of database: `sqlite` or `mysql` or 'pgsql' 'type' => 'sqlite', - # MySQL host. + # Database server 'host' => 'localhost', - # MySQL user. + # Database user 'user' => '', - # MySQL password. + # Database password 'password' => '', - # MySQL database. + # Database name 'base' => '', - # MySQL table prefix. + # Tables prefix (useful if you use the same database for multiple things) 'prefix' => 'freshrss_', - 'pdo_options' => array( + # Additional connection string parameters, such as PostgreSQL 'sslmode=??;sslrootcert=??' + # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS + 'connection_uri_params' => '', + + # Additional PDO parameters, such as offered by MySQL https://php.net/ref.pdo-mysql + 'pdo_options' => [ //PDO::MYSQL_ATTR_SSL_KEY => '/path/to/client-key.pem', //PDO::MYSQL_ATTR_SSL_CERT => '/path/to/client-cert.pem', //PDO::MYSQL_ATTR_SSL_CA => '/path/to/ca-cert.pem', - ), + ], - ), + ], # Configure the default feeds to which users will automatically be subscribed. 'default_feeds' => array( diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index 873fa21ff..0a918e887 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -47,6 +47,7 @@ class Minz_ModelPdo { $driver_options = isset($db['pdo_options']) && is_array($db['pdo_options']) ? $db['pdo_options'] : []; $dbServer = parse_url('db://' . $db['host']); $dsn = ''; + $dsnParams = empty($db['connection_uri_params']) ? '' : (';' . $db['connection_uri_params']); try { switch ($db['type']) { @@ -59,12 +60,12 @@ class Minz_ModelPdo { $dsn .= ';port=' . $dbServer['port']; } $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4'; - $this->pdo = new MinzPDOMySql($dsn, $db['user'], $db['password'], $driver_options); + $this->pdo = new MinzPDOMySql($dsn . $dsnParams, $db['user'], $db['password'], $driver_options); $this->pdo->setPrefix($db['prefix'] . $currentUser . '_'); break; case 'sqlite': $dsn = 'sqlite:' . join_path(DATA_PATH, 'users', $currentUser, 'db.sqlite'); - $this->pdo = new MinzPDOSQLite($dsn, $db['user'], $db['password'], $driver_options); + $this->pdo = new MinzPDOSQLite($dsn . $dsnParams, $db['user'], $db['password'], $driver_options); $this->pdo->setPrefix(''); break; case 'pgsql': @@ -75,7 +76,7 @@ class Minz_ModelPdo { if (!empty($dbServer['port'])) { $dsn .= ';port=' . $dbServer['port']; } - $this->pdo = new MinzPDOPGSQL($dsn, $db['user'], $db['password'], $driver_options); + $this->pdo = new MinzPDOPGSQL($dsn . $dsnParams, $db['user'], $db['password'], $driver_options); $this->pdo->setPrefix($db['prefix'] . $currentUser . '_'); break; default: |
