Skip to content

Commit b85f440

Browse files
authored
Fix: php artisan db command if no password (#55761)
If there is no password in the database connection, it will not be connected, and an error will be thrown.
1 parent 2dcbcec commit b85f440

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Illuminate/Database/Console/DbCommand.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,21 @@ public function getCommand(array $connection)
157157
*/
158158
protected function getMysqlArguments(array $connection)
159159
{
160+
$optionalArguments = [
161+
'password' => '--password='.$connection['password'],
162+
'unix_socket' => '--socket='.($connection['unix_socket'] ?? ''),
163+
'charset' => '--default-character-set='.($connection['charset'] ?? ''),
164+
];
165+
166+
if (! $connection['password']) {
167+
unset($optionalArguments['password']);
168+
}
169+
160170
return array_merge([
161171
'--host='.$connection['host'],
162172
'--port='.$connection['port'],
163173
'--user='.$connection['username'],
164-
], $this->getOptionalArguments([
165-
'password' => '--password='.$connection['password'],
166-
'unix_socket' => '--socket='.($connection['unix_socket'] ?? ''),
167-
'charset' => '--default-character-set='.($connection['charset'] ?? ''),
168-
], $connection), [$connection['database']]);
174+
], $this->getOptionalArguments($optionalArguments, $connection), [$connection['database']]);
169175
}
170176

171177
/**

0 commit comments

Comments
 (0)