You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DSN-based connection configuration is closer to what PHP does with PDO
objects under the hood and this allows the use of more scenarios such as socket
connections and databases out-of-the-box without user_backend_sql_raw
having to provide configuration parameters for each option.
|`db_type`|`postgresql` or `mariadb`|`postgresql`|
78
-
|`db_host`| your db host such as `localhost` or `db.example.com` or (only for PostgreSQL) path to socket, e.g. `/var/run/postgresql`|`localhost`|
79
-
|`db_port`| your db port |`5432`|
80
-
|`db_name`| your db name ||
81
-
|`db_user`| your db user ||
82
-
|`db_password`| your db password ||
83
-
|`db_password_file`| path to file containing the db password ||
84
-
|`mariadb_charset`| the charset for mariadb connections |`utf8mb4`|
85
-
86
-
* Values without a default value are mandatory, except that
87
-
* only one of `db_password` or `db_passowrd_file` must be set.
88
-
* Only the first line of the file specified by `db_passowrd_file` is read.
77
+
that *User Backend SQL Raw* will connect to. There are two mutually exclusive ways to configure the database connection:
78
+
1. PostgreSQL-like
79
+
* Set `dsn` (containing user and password) and CAN specify `db_user` and (`db_password` or `db_password_file`). Values in DSN have priority.
80
+
2. MySQL-like
81
+
* Set `dsn` (not containing user and password) and MUST specify `db_user` and (`db_password` or `db_password_file`).
82
+
83
+
*`dsn`: check how to construct DSNs for [PostgreSQL](https://www.php.net/manual/en/ref.pdo-pgsql.connection.php) and [MySQL](https://www.php.net/manual/en/ref.pdo-mysql.connection.php) Examples:
84
+
* connect to PostgreSQL via a socket with ident authentication which requires no user or password at all: `pgsql:host=/var/run/postgresql;dbname=theNameOfYourUserDb`
85
+
* connect to PostgreSQL via TCP and user/password authentication: `pgsql:host=localhost;port=5432;dbname=theNameOfYourUserDb;user=theNameOfYourDbUser;password=thePasswordForTheDbUser`
86
+
* connect to MySQL via socket which requires no user or password at all: `mysql:unix_socket=/var/run/mysql/mysql.sock;dbname=theNameOfYourUserDb`
87
+
* connect to MySQL via TCP and user/password authentication: `mysql:host=localhost;port=3306;dbname=testdb` and then also set `db_user` and (`db_password` or `db_password_file`)
88
+
*`db_user`: Needs only be set for "MySQL-type" databases and is the database user that will be used to connect to the database.
89
+
*`db_password`: Needs only be set for "MySQL-type" databases and is the password for the user that will be used to connect to the database.
90
+
*`db_password_file`: Can be set to read the password from a file. Has higher priority than `db_password`, but lower priority than password in DSN. So, for PostgreSQL-like database connections, don't specify the password in the DSN because it would override this. For MySQL-like connections, this one will have priority.
91
+
* Only the first line of the file specified by `db_password_file` is read.
89
92
* Not more than 100 characters of the first line are read.
90
-
* Whitespace-like characters are [stripped](https://www.php.net/manual/en/function.trim.php) from
93
+
* Whitespace-like characters are [trimmed](https://www.php.net/manual/en/function.trim.php) from
91
94
the beginning and end of the read password.
92
-
* If you specify a socket as `db_host` (only for PostgreSQL), you need to put
93
-
dummy values for the mandatory values, although they are not required for the
94
-
socket connection. This will be fixed in a future release.
95
+
96
+
For other databases check their [PDO driver documentation pages](https://www.php.net/manual/en/pdo.drivers.php) which in-turn link to their respective DSN references.
Copy file name to clipboardExpand all lines: appinfo/info.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ In contrast to the app *SQL user backend*, you write the SQL queries yourself. Y
14
14
The app uses prepared statements and is written to be secure by default to prevent SQL injections. It understands the most popular standards for password hash formats: MD5-CRYPT, SHA256-CRYPT, SHA512-CRYPT, BCrypt and the state-of-the-art Argon2i and Argon2id. Because the various formats are recognized on-the-fly your db can can have differing hash string formats at the same time, which eases migration to newer formats.
15
15
16
16
This app supports PostgreSQL and MariaDB/MySQL.]]></description>
if ($passwordIsSet === $passwordFileIsSet) { // expression is a "not XOR"
158
-
thrownew \UnexpectedValueException('Exactly one of ' . self::CONFIG_KEY_DB_PASSWORD . ' or ' . self::CONFIG_KEY_DB_PASSWORD_FILE . ' must be set (not be empty) in the config.');
159
-
}
160
-
161
-
if ($passwordIsSet) {
162
-
$this->logger->debug("Will use db password specified directly in config.php.");
163
-
return$password;
164
-
}
165
-
124
+
// Password from file (db_password_file) has higher priority than password from config (db_password).
166
125
if ($passwordFileIsSet) {
167
-
$this->logger->debug("Will use db password stored in file " . $passwordFilePath) . ".";
126
+
$this->logger->debug("Will read db password stored in file " . $passwordFilePath)
127
+
. ". Password from config file will not be considered. Password from DSN still has "
128
+
."priority.";
168
129
$error_message_prefix = "Specified db password file with path {$passwordFilePath}";
169
130
170
131
if (!file_exists($passwordFilePath)) {
@@ -189,17 +150,19 @@ public function getDbPassword()
189
150
fclose($file);
190
151
$this->logger->debug("Successfully read db password from file " . $passwordFilePath) . ".";
191
152
returntrim($first_line);
153
+
} elseif ($passwordIsSet) {
154
+
$this->logger->debug("Will read db password specified in config.php. Password from file"
155
+
." was not specified. Password from DSN still has priority.");
156
+
return$password;
157
+
} else {
158
+
returnfalse;
192
159
}
193
160
194
-
}
161
+
// Priority of password in the DSN over both passwords read here is
162
+
// implemented in the PDO implementation of PHP. It will simply ignore
163
+
// the password given as a parameter during PDO object creation and use
0 commit comments