Add support for DSN

This commit is contained in:
James Cole 2022-01-28 20:58:08 +01:00
parent 1bf3608142
commit 0bcc3240b7
No known key found for this signature in database
GPG Key ID: BDE6667570EADBD5
2 changed files with 8 additions and 0 deletions

View File

@ -69,6 +69,8 @@ DB_PORT=3306
DB_DATABASE=firefly
DB_USERNAME=firefly
DB_PASSWORD=secret_firefly_password
# leave empty or omit when not using a socket connection
DB_SOCKET=
# MySQL supports SSL. You can configure it here.
# If you use Docker or similar, you can set these variables from a file by appending them with _FILE

View File

@ -63,6 +63,12 @@ class CreateDatabase extends Command
$exists = false;
$checked = false; // checked for existence of DB?
$dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4', env('DB_HOST', 'localhost'), env('DB_PORT', '3306'));
if ('' !== env('DB_SOCKET', '')) {
$dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', env('DB_SOCKET', ''));
}
$this->info(sprintf('DSN is %s', $dsn));
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,